Skip to main content
1 of 5
Raja Gopal
  • 113
  • 1
  • 1
  • 8

Insert Featured image from Feed

I am importing Products through feed programmatically as follows

$request = wp_remote_get('myapiurl);
$response = wp_remote_retrieve_body( $request );

// decode the json

$json = json_decode($response, true);

// loop through the results

if( ! empty($json[ 'results' ])) {
    foreach($json[ 'results' ] as $data) {

        // gather data you need, make sure to sanitize it

        $post_data = array(
              'post_title' => $data[ 'post_title' ],
                'post_name' => $data[ 'post_name' ],
                'post_content' => $data[ 'post_content' ],
                'post_category' => $data[ 'post_category' ],
                '_price' => $data[ 'price' ],
                'post_location' => $data[ 'location' ],
                'post_stock' => $data[ 'stock' ],
                'post_year' => $data[ 'year' ],
                'post_images' => $data[ 'images' ],
                'post_status' => 'publish',
                'post_type' => 'product',
        );

        // create product or post and return the new ID

        $post_id = wp_insert_post($post_data, $wp_error);
    }
}

The issue i face was image not inserting in featured image

Kindly help me please

Raja Gopal
  • 113
  • 1
  • 1
  • 8