Use the wp_insert_post() function, which takes an array as a parameter.
3 | require (dirname( __FILE__ ) . '/wp-load.php' ); |
7 | 'post_title' => 'My New Post' , |
8 | 'post_content' => 'Lorem ipsum dolor sit amet...' , |
9 | 'post_status' => 'publish' , |
10 | 'post_date' => date ( 'Y-m-d H:i:s' ), |
11 | 'post_author' => $user_ID , |
12 | 'post_type' => 'post' , |
13 | 'post_category' => array (0) |
15 | $post_id = wp_insert_post( $new_post ); |
- post_title: the name of the post.
- post_content: the content of the post
- post_status: the post status (published, draft, etc)
- post_date: use date() or specify a custom date
- post_author: Author id of the post author
- post_type: Can be post, page, or a custom post type
- post_category: An array of categories ids