コアサーバーV2プランご契約でドメイン更新費用が永久無料

how to writes new posts into wordpress programatically

Use the wp_insert_post() function, which takes an array as a parameter.

1<?php
2/** Make sure that the WordPress bootstrap has run before continuing. */
3require(dirname(__FILE__) . '/wp-load.php');
4 
5global $user_ID;
6$new_post = array(
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)
14);
15$post_id = wp_insert_post($new_post);
16?>
  • 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