How do I set the content for a post of a particular CPT?

To update properties of a post in the database use wp_update_post.

// Update post 37
  $my_post = array(
      'ID'           => 37,
      'post_title'   => 'This is the post title.',
      'post_content' => 'This is the updated content.',
  );

// Update the post into the database
  wp_update_post( $my_post );

Just beware of the possibility of an infinite loop when updating a post.

Leave a Comment