## php – I can’t set image ad fatured programatically

Question

I have a problem when I try to set image as featured. I don’t know where is the fail, I upload the image from a URL in the same server and then try to set it as featured. The code upload the image but don’t set it as featured. The code I used is:

$fotoid = media_sideload_image($imagesres."/".$row->foto1,$restaurantid, '' );
$attach_id = wp_insert_attachment($fotoid, $row->foto1,$restaurantid);
$attach_data = wp_generate_attachment_metadata($attach_id, $row->foto1 ); wp_update_attachment_metadata($attach_id, $attach_data ); set_post_thumbnail($restaurantid, $attach_id);  Where$restauranid is the ID of the post. $imageres is the url of the image, and$row->foto1 is image title and extension.

Thanks!

0
2 weeks 2022-01-03T05:19:50-05:00 0 Answers 0 views 0