Add title, post content, and category like add_post_meta and update_post_meta

How can I update/add a new title, post content, and category to a post with hard PHP code similar to add_post_meta(), update_post_meta()?

Related posts

Leave a Reply

1 comment

  1. By using wp_update_post(), found in wp-includes/post.php:

    // Update post 42
    $post = array();
    $post['ID'] = 42;
    $post['post_category'] = array( ... );
    $post['post_content' ] = 'This is the updated content.';
    $post['post_title' ] = 'This is the updated title.';
    
    // Update the post into the database
    wp_update_post( $post );