Support » Plugins » Hacks » Display custom taxonomy based on custom meta box selection

  • I have a custom post type called “deli” and I have a custom taxonomy for this cpt called “deli-brands”.

    For “deli” cpt I created a meta box (select radio) with two different options “imported” and “domestic”.

    I need to display the taxonomies “deli-brands” based on the cpt meta box selection.

    ie. If I have taxonomies “Brand 1”, “Brand 2” and “Brand 3”, and post type called “Product 100” with meta box “domestic” selected and taxonomy “Brand 2” selected. I want to display on the page the taxonomy or taxonomies that have posts with “domestic” meta box selected. In this example, the result will be display on the page “Brands 2” taxonomy only.

    Does any body did something like this before?! Is it possible?!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    I think you have your terminology a little confused. There is little need to have a slew of taxonomies like you are proposing. All of that can easily be handled by a single hierarchical taxonomy with a slew of different terms to identify different brands etc.

    A similar error I believe is made when you have another post_type called “Product 100”. I don’t think you intend to register a custom post_type for every product, but to create a new deli post for each product. If I am wrong about either of these, my apologies. I would then like you to explain why such an unusual data structure is required so that I can best help you.

    But if I’m right, your coding life will be fairly easy, this is exactly what WP is meant to do. Your meta box is presumably saving the user selection somewhere. It’s usually post meta, but could be anywhere. If it’s post meta, you retrieve the value with get_post_meta(). Since you have a hierarchical taxonomy structure, getting terms related to the user selection is simple. They are the children of the main terms ‘imported’ or ‘domestic’. You get child terms using get_terms().

    On the flip side, to get all deli posts of all products assigned the Brand 2 term, you use WP_Query with the tax_query' argument for 'Brand 2' term in 'deli-brands' taxonomy and apost_type` argument for ‘deli’.

    That’s the basics. I’ve skipped over some of the details. If you have trouble filling in any of the gaps, just ask again with more specifics and someone should be able to help you.

Viewing 1 replies (of 1 total)
  • The topic ‘Display custom taxonomy based on custom meta box selection’ is closed to new replies.