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 ?
functions.php
file and call it on specific template. See this answer