-
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?
2 Answers
Too much for a comment, so I’ll leave it for an answer:
- You’re asking a lot of Qs that should actually be different Qs and not dumped into a single one.
- (Ad 1.) You don’t register “child” or “parent” taxonomies. You add (child-)terms to a hierarchical taxonomy via the WP Back-End UI. You can do it programmatically with
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. - (Ad 4.) You can query multiple taxonomies at one time as seen on the WP_Query article in Codex. This queries the taxonomy and all assigned posts. You can also query for terms that are inside a hierarchical taxonomy. But there are no “child” taxonomies. Only “child” terms. You can add those child terms to your
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. - (Ad 3.) As stated in other answers & comments to some of your other Qs, you’ll need to hook in stuff like
save_post
and similar. You’ll find enough answers here on WPSE that show you how. You’re close. - (Ad 2.) You’re mixing labels with actual arguments. The
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:
- Please care about your old Qs. We really got problems to lower the number of open & unanswered Qs. You should go back and try to work on your open Qs that have answers.
- Proper formatting is highly appreciated. Answerers invest their time & advice for free to help you solve your problem. Please put an equal amount of effort into asking and formating a Q.
- Be polite in your comments to an answer. This will a) motivate the answerer to offer further help and b) this is an open Q/A format and your Q is meant to help other users later to avoid asking the same Q again and instead just read your Q and the according answers. See your behavior when asking & commenting as something like your “buisness card”.