Using wp_insert_post, Featured Image not posted

Forums NextScripts API Forums – Google+, Pinterest, LinkedIn, etc.. Using wp_insert_post, Featured Image not posted

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #204013
    Dul
    Participant

      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 ?

      #204082
      Dul
      Participant

        Just 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

        #205220
        NextScripts.com
        Participant

          If 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.

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.