I have two taxonomies set up, Make and Model, and I need to associate each Model term with a specific Make term. I have a custom taxonomy field set up for Model, so you can pick which ever Make is associated, but now I’m having trouble displaying these on the front end. I need to display a select list filled with terms that match a specific make.
For example, I could have these Makes:
And these models:
The models are then linked to each make, like this:
Finally, on the front end, I’d want to display these something like:
I could just do a foreach loop for each make, then a foreach loop inside that that checks to see if the associated make matches the currently listing make, but that seems database heavy. I’d really like a way to just query for terms by their custom field value.
So I kind of simplified how I’m displaying these on the front end. In actuality, it’s displaying in three select fields, with each taxonomy in it’s own field, and then some jQuery to show and hide different fields based on the user’s selection of Make.
Honestly I did think about doing it that way, but I didn’t want me client to be able to set up levels deeper than needed (for example, if I made it hierarchical, they could set up Honda > Civic > Accord > Fit > Element, and just keep going down).
Maybe I’ll just switch to hierarchical if this can’t be easily done; I can always just warn my client that making deeper levels of makes/models could break things.
The way I see it is that you could either switch to hierarchal single tax, do the “hacky” solution you have set up or switch so that your client sets the models on the make term instead.. It will require them to go into the make term after the model term has been created but will allow you to optimize the code since then you can just loop through each make and spit our it’s relational models.
OR go your own route with a custom SQL 🙂 But honestly SQL isn’t my strong suite..
Viewing 4 posts - 1 through 4 (of 4 total)
The topic ‘List all terms that who's custom field has a specific value’ 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