“Undefined index: path” on wp_insert_post

I’m trying to create a WordPress post using PHP, and something’s going wrong and I can’t figure it out. My background is not PHP, and no traceback is being delivered to me–just this error by itself:

Error: Undefined index: path

Here is my post creation code:

Read More
function generate_query_args($campaign_id, $user_id) {
    $query_args = array(
        'post_parent' => $campaign_id,
        'post_author' => $user_id,
        'posts_per_page' => -1,
        'post_status' => 'publish', /*array('publish'),*/
        'paged' => '',
        'log_type' => 'sale',
        'post_title' => 'Autogenerated by Heroku setup',
        'post_content' => '',
        'post_excerpt' => '',
        'tax_query' => array(
            array(
                'taxonomy' => 'edd_log_type',
                'field' => 'slug',
                'terms' => 'sale'
            )
        )
    );
    return $query_args;
}

$post_id = wp_insert_post(generate_query_args($campaign_id, $user_id));

As far as I can tell from the docs, I’m doing everything I’m supposed to be.

Update:

This is the entirety of what I run and see in return:

>> $post_id = wp_insert_post($query_args, true);
Error: Undefined index: path

I’m using WordPress console.

More information:

WordPress 3.9.1 running Fundify Child Theme theme.

Plugins (there are a lot of them, not my WP site):

Admin Bar Disabler, Akismet, Astoundify by Crowdfunding Custom Fields, BAW Login/Logout Menu, Coming Soon, CRED Frontend Editor, Crowdfunding by Astoundify, Dropifi Contact Widget, Easy Digital Downloads, Easy Digital Downloads – Record Test Payments, Easy Digital Downloads – Stripe Payment Gateway, Google Analytics for WordPress, Gravity Forms, Gravity Forms + (More) Stripe, Gravity Forms + Stripe Connect, Gravity Forms MailChimp Add-On, Module Manager, Nav Menu Roles, Peter’s Login Redirect, Restrict Content Pro, Restrict Content Pro – Math Verification, Restrict Content Pro – Stripe, Revolution Slider, Seed Prod Coming Soon pro, Simple Tooltips, Soundcloud Shortcode, TinyMCE Advanced, Types, Ultimate Addons for Visual Composer, User meta shortcodes, WordPress Console, WordPress SEO, WPBakery Visual Composer, WP Views

Post-mortem:
Ultimately, this may have been an error with the Console plugin, since when I simply ran the code as part of WordPress, it ended up working.

Related posts

Leave a Reply

1 comment

  1. wp_insert_post() should be used like this:

    $post_data = array(
        'post_status'           => 'draft', 
        'post_type'             => 'post',
        'post_author'           => $user_ID,
        'ping_status'           => get_option('default_ping_status'), 
        'post_parent'           => 0,
        'menu_order'            => 0,
        'to_ping'               => '',
        'pinged'                => '',
        'post_password'         => '',
        'guid'                  => '',
        'post_content_filtered' => '',
        'post_excerpt'          => '',
        'import_id'             => 0
    );
    
    $post_id = wp_insert_post( $post_data );
    

    For a full list of what you can include in the $post_data array see: http://codex.wordpress.org/Function_Reference/wp_insert_post