-
Should I register both parent and child as
'hierarchical' => true
, if there’s no grandchild? -
If “Movie” is the top level taxonomy, when I register a child, is it as simply as:
'parent_item' => __( 'Parent Movie' )
? -
How to automatically asign a child taxonomy to a post?
So far, I figured out how to asign a taxonomy to a post, but, does this work fine with child taxonomy?wp_set_object_terms($post_ID, $cat, 'category');
-
If I query a parent taxonomy, will the child be included in the results or not?
-
If the taxonomies are not listed in the
args
ofregister_post_type
, will they still work?
Leave a Reply
You must be logged in to post a comment.
Too much for a comment, so I’ll leave it for an answer:
wp_set_post_terms();
,wp_set_object_terms();
, or other functions, but that’s more internal stuff and tough to handle as you’d need to check on every request if it already exists or not (adds DB-queries), so it’s not really recommended as you can’t do it on theme activation as long as WP doesn’t offer a hook there.tax_query
arguments. Doing something likeif is child of
can be done with functions likeget_term_children();
. If you link to a term archive, you can modify the query (search WPSE) to include child terms as well.save_post
and similar. You’ll find enough answers here on WPSE that show you how. You’re close.parent_item
andparent_item_colon
arguments are meant to set your custom text and can’t register “child” taxonomies. They’re only used to modify the default text you see in the admin UI.Sidenotes:
If you register a taxonomy as
hierarchical=>true
, it will become a category, and you can form parent – child relationships within that taxonomy. Whereas if you register a taxonomy ashierarchical=>false
, it will become a tag, meaning, no parent – child relationships. You may need to get a term’s id, use the function term_exists, then use wp_insert_term to insert a new term, with parent as the id you got using term_exists.