I’m using this code:

$post = array(
        'post_content' => $desc,
        'post_title' => $name_new,
        'post_status' => 'publish',
        'post_type' => 'portfolio_page',
        'tax_input' => array('portfolio_category' => array($cat, 18, 19))
    );

    if (!$post_id = wp_insert_post($post)) {
        die('Error');
    }

which is working perfectly when executed via web browser. Unfortunately I need to execute it via shell, and what is happening is the post is inserted but the tax_input is ignored.

Any suggestion?

thanks a lot

2 Answers
2

This is typical issue. While wp_insert_post() won’t check for user capabilities to insert post, the tax_input part actually will check if user has permission to manipulate those specific taxonomies.

If you don’t have user logged in state replicated in your shell context then it will fail accordingly.

The solution is to insert post first, then assign terms via separate function calls which won’t check capabilities (yeah, it’s not consistent).

Leave a Reply

Your email address will not be published. Required fields are marked *