How to get parent taxonomy

The essence of the problem was that you need to display the parent taxonomy, the child taxonomy, which owns the custom post type, on the page of the post itself. Those. we have a post, call it “professional”, it belongs to the sub-category “cleaning”, the sub-category “cleaning” is a subsidiary of the category “services”. We need on the post page to display the category to which the post belongs and its parent category.

So, the code:

If in a nutshell, we define a child taxonomy ID, and through get_ancestors determine the ID of the parent taxonomy.

Having an ID, we display the data we need.
This code needs to be inserted into the functions.php file of your theme.

The function call can be made from anywhere in the template:

© Copyright 2014 - All rights reserved