Support » Plugins » wp_update_post updates not shown

  • Hi,

    I’m writing a plugin that uses wp_update_post to add tags to an existing post.
    However, the modifications are stored in the database es a “revision”, and these do not shown on the “edit post” page. It looks as though nothing had happened.

    What am I doing wrong ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Does anybody know anything about wp_update_post or wp_insert_post?? I see that most of the questions concerning these functions go unanswered on these forums… Are we too stupid to be able to use them properly, or are they so arcane that no one knows anything about them?

    I am having a similar problem with updating the post_date and post_date_gmt. I am using wp_insert_post to create classified ads and then updating them with their actual publication date using wp_update_post.

    The documentation says that it will return the id of the post it is successful. In my case it is returning the ID, but it the publication date is still current date.

    $id = wp_insert_post( $postObj );

    $post_date = date("Y-m-d H:i:s", strtotime($start_date));
    $post_date_gmt = date('Y-m-d H:i:s',strtotime($start_date . " +5 hours" ));

    $my_updated_post = array();
    $my_updated_post['ID'] = $id;
    $my_updated_post['post_date'] = $post_date;
    $my_updated_post['post_date_gmt'] = $post_date_gmt;
    $my_updated_post['post_status'] = 'publish';


    $update_id = wp_update_post( $my_updated_post );

    echo("update id = $update_id<hr />\n");

    OK now it works . . . on wp_insert_post I was setting post_status = ‘draft’, then on wp_update_post I was setting both post_status = ‘publish’ along with the post_date to a date in the past.

    Once I changed the post_status = ‘publish’ on my wp_insert_post and removed the post_status = ‘publish’ on the wp_update_post it worked. wp_insert_post must be ignoring what I am setting for the post_date.

    $postObj['post_status'] = 'publish';

    $id = wp_insert_post( $postObj );

    /* $my_updated_post['post_status'] = 'publish'; */

    I’m going to have to find another work around because I was using the draft_post hook to email subscribers of new ads. The problem I was having is that every ad was being emailed regardless of the past publication date.

    I’ll try using the edit_post hook to notify users of only today’s ads.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_update_post updates not shown’ is closed to new replies.