Hi guys i am trying to add post in WordPress. I used CPT UI to created/register custom post type and custom taxonomies. I used the code below to add my post.
$post = array(
'post_title' => $title,
'post_content' => $description,
'post_status' => 'publish',
'post_type' => 'questions',
);
$post_id = wp_insert_post($post);
$check_if_save = wp_set_object_terms( $post_id , array(10,11 ), 'question-category' );
But when this code executed $check_if_save->get_error_message()
always returns an Invalid Taxonomy
. I also check the get_taxonomies()
but my custom taxonomy is not included. I also register taxonomy manually and follow this link as a solution. But i doesn’t work for me.
Any ideas why this happen?
Make sure you’re creating your taxonomies before the custom post type they belong to.