Home › Forums › Front-end Issues › List all terms that who's custom field has a specific value
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.
Not that I want to be “that guy” but why don’t you just use a single hierarchal taxonomy for both make and model?
That way your interactions with it in code will be very simple and as an added bonus you’ll be able to get sweet URL structures like
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..
You must be logged in to reply to this topic.
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’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.