0

I am using custom fields with custom taxonomy... And needed to asign new post to custom category.

As you know default wp_insert_post not working with 'post_category' with custom posts. So we need to asign with wp_set_object_terms.

But there is big problem, when i put for example in function.php file this code:

wp_set_object_terms($post_ID, array(1,5), 'custom_cat_taxonomy')

its not working at all

and the error is: WP_Error Object ( [errors] => Array ( [invalid_taxonomy] =>

when I put this code in for example in single.php it works and assigns category to post.

any ideas how to solve it ?

3
  • I found that when I register a new taxonomy. In functions.php i printed all taxonomy and there are no registered taxonomies, only default taxonomies. Array ( [category] => category [post_tag] => post_tag [nav_menu] => nav_menu [link_category] => link_category [post_format] => post_format )
    – andys
    Commented Dec 14, 2013 at 9:22
  • What action are you hooking your taxonomy registration function to? Commented Dec 14, 2013 at 14:29
  • You can make logic in functions.php file and call it on specific template. See this answer Commented Dec 14, 2013 at 15:29

0

Your Answer

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

Browse other questions tagged or ask your own question.