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.

  • 1
    That is a permissions error. It occurs when you try to access an admin page that you don't have permission to access. Can you please explain the context and post more code. While what you are doing is almost certainly pretty sketchy, it does work when I test it, though $_SERVER['DOCUMENT_ROOT'] was not correct on my server so I had to edit that.
    – s_ha_dum
    Sep 7, 2013 at 15:33
  • A better thing you can do is use a web-service, where you can interact with your worpdress site, "API like style"
    – jepser
    Sep 7, 2013 at 20:58
  • For what I am doing the XML-RPC won't do the job. If it is a permission error what do I need to do in order to be able to use this? It doesn't matter if it is sketchy, it isn't publicly available.
    – Rambomst
    Sep 8, 2013 at 1:33

1 Answer 1


Just add this code

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.