I’m having an issue trying to get the slug of the ancestor category of a taxonomy field created with Advanced Custom Fields Pro (ACF).
I have a website that is using the default 'category' taxonomy of Wordpress, and the taxonomy has various levels of hierachy:
1. Cat
1.1 SubCat
1.1.1 Subcat
1.1.2 Subcat
1.1.1.1 Subcat
1.1.1.2 Subcat
1.2 Subcat
1.2.1 Subact
1.2.1 Subcat
2. Cat
2.1 Subcat
2.2 Subcat
3. Cat
3.1 Subcat
3.1.1. Subcat
3.1.2. Subcat
4. Cat
etc.
I have a repeater field called “Slides” that contains an ACF taxonomy subfield. Getting the taxonomy term from that subfield and display it in the frontend is easy with:
<p><?php the_sub_field('cat-field'); ?></p>
But...: i also need to get the slug of the ancestor category of that taxonomy term (just the immediate one single level UP, not the top-most). I need this slug to use it as a CSS class.
<p class="cat-{slug-of-the-ancestor}">Taxonomy term</p>
Can anybody help me please? Thanks in advance.