Support

Account

Home Forums Front-end Issues List all terms that who's custom field has a specific value

Solving

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:

    Honda
    Ford
    Toyota

    And these models:

    Civic
    Accord
    Taurus
    Escort
    Prius
    Corrola

    The models are then linked to each make, like this:

    Civic [Honda]
    Accord [Honda]
    Taurus [Ford]
    Escort [Ford]
    Prius [Toyota]
    Corrola [Toyota]

    Finally, on the front end, I’d want to display these something like:

    Honda
    – Civic
    – Accord
    Ford
    – Taurus
    – Escort
    Toyota
    – Prius
    – Corrola

    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.

  • Hi @revxx14

    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 /make/honda/civic/.

  • 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.

  • Yeah,

    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.