• After I upgraded to WP 3.9, one of my plugins generated the following error:

    Fatal error: Call to undefined function is_user_logged_in() in /home/realizar/public_html/wp-includes/post.php on line 2185

    After some reserch, I found out that the error is caused by the wp_insert_post:
    I read the manual, but I cannot find out what I’m doing wrong. Here is the code I use:

    $newPost = array(
        'post_title' => $articleTitle,
        'post_content' => $articleText,
        'post_status' => $post_status
    );
    wp_insert_post($newPost, true);


    Thanks for any advice!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I dont believe you need the ‘True’ inside of wp_insert_post.

    Try:

    $newPost = array(
        'post_title' => $articleTitle,
        'post_content' => $articleText,
        'post_status' => $post_status
    );
    wp_insert_post($newPost);

    Thread Starter azolee

    (@azolee)

    Hi Evan!
    It does not help, unfortunately. The same error I got now.

    This is because the file with that function has not been included yet! The best thing to do is this

    add_action('wp_loaded', 'process_post');
    
    function process_post(){
        switch_to_blog(1); // only if you're using multisite
        $newPost = array(
            'post_title' => 'test',
            'post_name' => 'test_1', // The name (slug) for your post
            'post_status' => 'draft' ,
            'post_type' => 'my_post_type', // usually 'post'
        );
        wp_insert_post($newPost);
        restore_current_blog(); // only if you're using multisite
    }

    This makes the post add itself after everything (including other plugins potentially with custom post types) has been loaded.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_insert_post error in plugin after updating to WP 3.9’ is closed to new replies.