Support

Account

Home Forums Front-end Issues List terms filtered by taxonomy

Solved

List terms filtered by taxonomy

    • anarita

    • January 30, 2014 at 1:13 am

    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

    • Elliot

    • January 30, 2014 at 10:05 am

    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

    • anarita

    • February 3, 2014 at 10:02 am

    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

    • Elliot

    • February 4, 2014 at 9:23 am

    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

    • anarita

    • February 6, 2014 at 11:58 pm

    It’s the project that contains the taxonomy field. It’s not multiselect. Each project has only one client.

    • Elliot

    • February 7, 2014 at 1:31 pm

    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

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.