Getting error when using wp_insert_post()

Question

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.

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/getting-error-when-using-wp_insert_post/">

Getting error when using wp_insert_post()</a>
0
, , , Rambomst 2 months 0 Answers 55 views 0

Leave an answer