Home › Forums › Front-end Issues › List terms filtered by taxonomy
Hi, thank you for a great plugin.
I created a taxonomy field with ACF – “Clients” – to categorize taxonomy terms – “Projects”. IE, each project is attributed to a client by way of a taxonomy field. Now I would like to list all projects of each client in a template. How can I do this? I’m having trouble finding code examples, as it is uncommon on wordpress to have a list taxonomy terms filtered by another taxonomy.
Thank you,
Ana Rita
Hi @anarita
Can you please clearly explain the data structure?
What from the above are post types and what are taxonomies?
Where do you want to display this list of projects?
Thanks
E
Hi @elliot,
I’ve since found a different solution. But as this can be of utility for others, I’ll give more info. None of the above are post types. They are both taxonomies. With ACF we have the ability to add custom fields to taxonomies. And so I’ve added a taxonomy field type to a taxonomy. I’ve categorized “projects” (taxonomy) with their respective “clients” (taxonomy). I was then asking for a way to list “projects” belonging to a client on a “client” taxonomy template.
Thank you,
Ana Rita
Hi @anarita
The code greatly depends on the direction of the relationship. Does the project contain the taxonomy field, or does the client?
Is this a multi select taxonomy field?
Thanks
E
It’s the project that contains the taxonomy field. It’s not multiselect. Each project has only one client.
Hi @anarita
Currently, WP does not provide a termmeta table, so a meta query cannot be performed on a term query.
What I would do is load all terms from the ‘project’ taxonomy, then loop over them and load in the ‘client’ for each one using the get_field
function.
You can then simply compare the value, and continue
the loop to avoid it, or display the project data if a match was found.
Thanks
E
The topic ‘List terms filtered by taxonomy’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.