WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Question about wp_insert_post

[Resolved] Question about wp_insert_post

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m going to guess that the twitter tools and wpbook plugin functionality occurs when the publish_post action occurs. So if those post metas aren’t set at that time, it probably won’t do anything with your post. Obviously you could test this out and verify that this is the case. Something you may want to consider is to set your post’s status to “pending” or “draft”, insert it, set your post metas, then use the wp_publish_post($new_post_id) function to publish the post.

    giant slayer
    Member

    @giant-slayer

    So what if I did something like this?

    'post_date_gmt'=>strtotime('+5 minutes');
    'post_status' => 'future',

    I set the post status to future and set the post time 5 minutes later. Then when wp_insert_post is called, the post is created, the meta is added, and then the when the 5 minutes passes, the post is published.

    I would imagine that would work too, but then you’d have to wait 5 minutes (or however long you set) for your post to show up.

    giant slayer
    Member

    @giant-slayer

    What about something like this? Then I could leave the post status to publish and have no time delay.

    function insert_required_meta_data($id) {
        add_post_meta($new_post_id, 'aktt_notify_twitter', 'yes');
        add_post_meta($new_post_id, 'wpbook_fb_publish', 'yes');
    }
    add_action('pre_post_update', 'insert_required_meta_data');
    wp_insert_post( $my_post );
    giant slayer
    Member

    @giant-slayer

    This worked like a charm.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Question about wp_insert_post’ is closed to new replies.