Getting error when using wp_insert_post()

When I use wp_insert_post() I get a white page that says “Are you sure you want to do this?”. I get no PHP errors. I am using this outside of wordpress and have wp-load.php as well as /wp-admin/includes/file.php included.

My code looks like this.

Read More
require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-load.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-admin/includes/file.php";
$imagePost = array(
        'post_title' => "Test",
        'post_content' => 'Content added later.',
        'post_status' => 'publish',
        'post_author' => 1,
        'tags_input' => "'test'",
        'post_category' => array(1),
        'post_type' => 'post'
);

$postID = wp_insert_post($imagePost, true);

Any help is much appreciated.

Related posts

1 comment

  1. Just add this code

        $post_id = wp_insert_post($arg);
        if(!is_wp_error($post_id)){
          //the post is valid
        }else{
          //there was an error in the post insertion, 
          echo $post_id->get_error_message();
        }
    

Comments are closed.