› Forums › NextScripts API Forums – Google+, Pinterest, LinkedIn, etc.. › Using wp_insert_post, Featured Image not posted
- This topic has 2 replies, 1 voice, and was last updated 10 years, 6 months ago by NextScripts.com.
- AuthorPosts
- May 17, 2014 at 8:20 am #204013DulParticipant
Hi,
I’m posting from front page using wp_insert_post.
Since wp_insert_post doesn’t have parameter for featured image, I use update_post_meta to set the featured image. The post is posted to social media successfully. But the problem is, it seems your plugin doesn’t recognize the featured post.I assume your plugin runs right after the wp_insert_post so, it doesn’t recognize the featured image since it hasn’t been set.
Is there any way to delay your plugin so it cant run after I set the featured image? Or is there any trigger to make the plugin run manualy after update_post_meta ?
May 17, 2014 at 11:26 am #204082DulParticipantJust realized I post in wrong forum.
Anyway, I managed to make it work by delaying my post by 30 seconds.
//Since we have issue with Next Scripts: Social Networks Auto Poster and our featured image
//Delay the post for 30 seconds to make the plugin see the featured post
$post_date_delayed = current_time('timestamp') + 30;// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => wp_strip_all_tags($title),
'post_content' => $comment,
'post_category' => $cat, // Usable for custom taxonomies too
'tags_input' => $tags,
'post_status' => 'future', // Choose: publish, pending, future, draft, etc.
'post_type' => 'post', //'post',page' or use a custom post type if you want to
'post_date' => date('Y-m-d H:i:s', $post_date_delayed),
);//SAVE THE POST
$pid = wp_insert_post($new_post);
Just in case someone have similar problem like me
May 19, 2014 at 10:26 am #205220If featured image is not set at the time our plugin runs then of course it won’t get it. You can either set a delay (what you already did) or set featured image before publishing the post.
- AuthorPosts
- You must be logged in to reply to this topic.