Support

Account

Home Forums General Issues Filter Relationship field by a taxonomy choice

Helping

Filter Relationship field by a taxonomy choice

  • Hi

    I’m looking to filter down my relationship results for my writers to pick from based by a taxonomy that is picked.

    For a little information about how my site is setup, I have a Custom Post type called “Talents” which has a ton of posts each post is a talent.

    I have a custom taxonomy called “Heroes”

    What I’m doing is having it so on my posts if a contributor is writing a guide based off a Hero I would like to only show the “talents” in the relationship select field for that hero which they would select the hero in the “Heroes” taxonomy.

    The problem is with the relationship field is I have to select the “Hero” in the backend based upon selecting one “hero” from the Filter by taxonomy in the Relationships but if I did that it would only show the talents for which ever hero I selected when creating the Field, where I need that to be based of what the writer selects in the guide based upon my “heroes” taxonomy.

    So on the post if the user selects “Hero 3” in the Heroes taxonomy I want the relationship field I’ve made to only show the “Talents” from “Hero 3”

    I can’t seem to figure out how to make the Taxonomy filter in the Relationship field dynamic based off another variable such as my “Hero” taxonomy.

  • You would need to create custom JavaScript for the field in question, make an AJAX request and do your own query for the select2 field of the taxonomy field. This isn’t something that you can to with ACF. You can start here: http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    Another way you could do this is to use a regular select field that you dynamically populate from the first taxonomy then create a conditional select fields that show/hide based on the selection of the first select field. A bit complicated to build.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Filter Relationship field by a taxonomy choice’ is closed to new replies.