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.

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.

Topic wp-insert-post fatal-error php errors Wordpress

Category Web


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();
    }

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.