Set Featured Image from third party Programmatically

Set Featured Image from third party Programmatically
$args = array(
          'post_type'      => 'businesses',
          'posts_per_page' => -1, 
          'post_status'    => 'publish',
          //'offset'         => 15
      );

      $query = new WP_Query($args);

      if ($query->have_posts()) {
          while ($query->have_posts()) {
              $query->the_post();

              //echo get_the_id().'
'; //$postid = 13781; if( get_the_id() == $postid ){ $imagepath = get_field('image_path'); $photopath = get_field('photo_file'); $imageurl = $imagepath.$photopath; echo $imageurl; require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); // load the image $result = media_sideload_image($imageurl ,$postid,'featured image', 'id' ); update_post_meta($postid , '_thumbnail_id',$result ); echo $result; } } } else { }

screen144

Leave a Reply

Your email address will not be published. Required fields are marked *