Wordpress用PHP创建帖子

I want to make a custom PHP script, what can make a post for wordpress.

Here is my code from official page, but its not working:

require("wp-includes/post.php");

// Create post object
$my_post = array(
  'post_title'    => "mytitle",
  'post_content'  => "mycontent",
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array( 1 )
);

wp_insert_post( $my_post );

The error is:

Fatal error: Call to undefined function get_current_user_id() in /home/MyUser/public_html/wp-includes/post.php on line 2897

What im doing wrong?

The problem is probably that you are not logged in as a backend user. The script is trying to get a backend user id. There has to be a user logged in to create a post. Each post needs a userid, this is used to set the author of the post.

Also are you trying to execute this script inside a plugin or outside wordpress?