Is there any way to get only parent terms from custom taxonomy or category?
Leave a Reply
You must be logged in to post a comment.
Is there any way to get only parent terms from custom taxonomy or category?
You must be logged in to post a comment.
Yes, just pass in the parent parameter to
get_terms
when you call it, as Michael pointed out.Since WP 4.5 this is the recommend usage:
Prior to WP 4.5 this was the default usage:
Will return all terms that have a parent value of
0
, ie. top level terms.use the ‘parent’ parameter:
http://codex.wordpress.org/Function_Reference/get_terms
or
http://codex.wordpress.org/Function_Reference/get_categories
for woocommerce email templates use the following:
For this demonstration, we will assume that we have a taxonomy called “Books”.
And we might have a hierarchy of:
We want to get the parent term of the taxonomy “Books” of the current post.
Then you just run on you template like this:
or