How to get parent taxonomy

/, Wordpress/How to get parent taxonomy

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:

By |2019-03-29T13:39:45+00:00March 29th, 2019|Useful hooks, Wordpress|0 Comments

About the Author:

I web developer specializing in developing websites for small to medium business, and from simple blog to a multi-level online shop on Wordpress, Joomla and other CMS. I develop responsive websites using the most current technologies in development sites. My previous work experience provided me with self-discipline, perseverance, thinking outside the box, and leadership skills that allow me to effectively communicate with others to achieve our goals. My clients are always 100% satisfied. I am a fast learner. I am one of those who enjoys challenges and thrives in a fast paced, goal oriented environment. Currently have experience working with PHP, HTML, CSS, JavaScript, jQuery, Wordpress, Drupal, Joomla.

Leave A Comment