Set terms in a custom post

I know this is an old question, but the tax_input array should probably look like this since it appears to be hierarchical like a category: ‘tax_input’ => array(‘artist-category’ => array( 3 ) //use the ID of the category, not the name of the category From WordPress Codex on wp_set_post_terms If you want to enter terms … Read more

Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?

Unfortunately, this is not possible, at least not safe. The function wp_insert_term( $term, $taxonomy, $args = array() ) that handles the creation of taxonomies provides a few filters and hooks, but the only one before the creation of the term in the database is $term = apply_filters( ‘pre_insert_term’, $term, $taxonomy ); As you can see, … Read more

get_term and get_term_by return null or false, even though term exists

To use get_term_by we need the term object before it gets deleted. Therefore, we should use the action hook delete_term_taxonomy that runs before the term is deleted. Now, we can go ahead and perform some tasks such as deleting all the postmeta related to the term being deleted. The code is: add_action( ‘delete_term_taxonomy’, function($tt_id) { … Read more

Same taxonomy for different object types

Those are different object types that belong to different tables and hence can have same primary key ID. –> Even though these are different types, all are being stored in one table i.e. wp_posts with post_type = the different types. Check the table structure for clarity. So there won’t be any same ID conflict. if … Read more

Get_terms stopped working after WP 4.2

I’ve got this fixed now. Managed to talk with my old developer and he added this: $termsById = array(); foreach ($terms as $t) { $termsById[$t->term_id] = $t; } I had to add this new variable where $terms was previously used on line 14. Thanks for your help everyone, I appreciate the effort.