• I’m working with a unique usecase: I have three taxonomy types for a custom post type.

    The usecase is the user wants it so Tax A’s term will dictate which of Tax B’s terms will display.

    For instance, if Tax A term 1 is picked, only Tax B terms a,b,c,d show up. If Tax A term 2 is picked, Tax B terms b,f,g,h,i show up.

    To add on top of this, the user also wants to be able to assign a sub-taxonomy to Tax B. For instance, on a custom post with Tax B terms b,f, and i selected, they want Tax B term b to have Tax C term ii selected, for Tax B term f, Tax C term iii selectred, and Tax B term i, Tax C term iv selected.

    What’s the best way to program what my user wants?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The easiest way, if you can make it work, is to actually manage all terms as one hierarchical taxonomy. Then you can maintain parent-child relationships. For example, assigning term 1 to a post could mean all of term 1’s children are displayed with the post. The relations can be carried any number of levels deep, and it’s possible to only get immediate children, excluding grandchildren etc., so an assigned child term can have its own children displayed without impacting its siblings or parent.

    If a single taxonomy will simply not work, you would need to maintain relationships yourself. This could be done through term meta. For example, taxonomy A’s term 1 could have term meta values pointing to taxonomy B’s terms a, b, c, and d. The post template could, upon finding term 1 is assigned, get the term meta and output the related term names associated with the saved meta values.

    There is no UI by default for term meta, but the term edit screen has several actions you can hook to add fields for meta values. Then use the “edit_term” action to save the added field values upon submittal.

Viewing 1 replies (of 1 total)
  • The topic ‘Conditionally relating a taxonomy term to another taxonomy term’ is closed to new replies.