Set Featured Image of a post

To set a featured image when creating a post using wp_insert_post(), you can use the set_post_thumbnail() function

// Create the post
$post_id = wp_insert_post($args);

// Check if the post was created successfully
if (!is_wp_error($post_id)) {
    // Set the featured image
    if ($image_url) { // $image_url should be the URL of the image you want to set as the featured image
        $image_id = media_sideload_image($image_url, $post_id, '', 'id'); // Upload and attach the image
        if (!is_wp_error($image_id)) {
            set_post_thumbnail($post_id, $image_id); // Set the uploaded image as the featured image
        }
    }
}

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino