0

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.

Fedegiro
  • 53
  • 3
  • 9
  • Your question is confusing one can you please let me know what do you want here? – dipmala Jun 11 '18 at 10:33
  • @dipmala i just edited the question, let me know if now is clear. – Fedegiro Jun 11 '18 at 22:08
  • you have you cat ID - So check this answer out : https://stackoverflow.com/a/19961973/4244684 – Stender Jun 12 '18 at 06:46
  • the ACF taxonomy field doesnt seems to work with the get_the_category function, btw i am not making a query. https://www.advancedcustomfields.com/resources/taxonomy/ – Fedegiro Jun 12 '18 at 20:03
  • also... the cat ID is dynamic - depends on the category chosen in the acf taxonomy field in the backend. https://www.advancedcustomfields.com/resources/taxonomy/ – Fedegiro Jun 12 '18 at 20:14

0 Answers0