Support » Fixing WordPress » set_post_status() function?

  • I’m working on a plugin that changes a posts status (draft / published) based on its meta data.

    While there is a handy function to get a posts current status:
    I can’t find any record of a similar function to allow you to set the status.

    I’m currently using a custom DB call (below) but I’m worried that other crucial function calls are not happening!

    						array( 'post_status' => 'draft'),
    						array( 'id' => $id ),
    						array( '%s' ),
    						array( '%d' )

    Does any one know a better way to achieve this please?


Viewing 1 replies (of 1 total)
  • Moderator keesiemeijer


    Try wp_update_post

    // Update post
      $my_post = array();
      $my_post['ID'] = $id;
      $my_post['post_status'] = 'draft';
    // Update the post into the database
      wp_update_post( $my_post );

Viewing 1 replies (of 1 total)
  • The topic ‘set_post_status() function?’ is closed to new replies.