3

I'm trying to insert custom taxonomies using wp_insert_post() and the tax_input argument, but it doesn't work. I want to set a post to a custom taxonomy ('types') and a category ('cars')

$new_post = array(

        'post_title'    =>   $title,

        'post_content'  =>   $description,

        'tax_input' =>   array('types' => array('cars')),  

        'post_status'   =>   'pending',          

        'post_type' =>   'vehicles'  

        );
4
  • 1
    where are you trying to use this? if the current user doesn't have permission to assign terms in that taxonomy, it will fail.
    – Milo
    Mar 27, 2014 at 18:17
  • Everything else, except that line of 'tax_input' goes perfectly. I test it as admin, so maybe that is not the problem :/ ? Mar 27, 2014 at 18:40
  • Is "cars" a category or a term in your custom taxonomy?
    – s_ha_dum
    Mar 27, 2014 at 18:44
  • I guess it's a term. My custom taxonomy is called 'types' and my categories are as followed: cars, trucks, etc. Mar 27, 2014 at 20:13

1 Answer 1

3

I find the answer. After building my arguments for wp_insert_post() function and passed it to a variable $pid i set the following line after that and everything works slightly.

wp_set_object_terms($pid, 'cars', 'types', true);

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.