• Resolved lddawg2727

    (@lddawg2727)


    Hi, your plugin is awesome! In your bidirectional description you mention taxonomies however I’m a but confused on how to set that up. I have 2 custom post types (company and podcast) and a custom taxonomy (industry). I want to add a taxonomy to either post type when the other post type taxonomy is set. I use the taxonomy to filter archive pages, etc.

    Is this possible?

    ref: https://www.acf-extended.com/features/field-settings/bidirectional-fields

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! I’m glad you enjoy ACF Extended!

    The bidirectional setting allow to set a 2 way relationship. That means you can retrieve the relationship value from both objects.

    For example, in your case, you can set a relationship between Company <> Podcast. If you set Company A <> Podcast C, then you can retrieve “Company A” from “Podcast C” and “Podcast C” from “Company A”.

    In some way, the native WordPress logic between a Post Type and a Taxonomy is a bidirectional relationship too. Since you can retrieve Terms from a Post, and retrieve Posts from a Term.

    The bidirectional setting is compatible with the ACF Taxonomy Field since you can have a relationship between two taxonomies. For example: Taxonomy Continents <> Taxonomy Countries. Or a relationship between User <> Taxonomy.

    In your case, what you’re asking is a triangular relationship, which is more complex. There’s no way to achieve it directly from the UI, you’ll have to add some code. A logic that would work in your case:

    Setup a bidirectional relationship between Company <> Podcast. Then set the values (Company A <> Podcast C for example).

    You can then use the set_object_terms hook, so everytime a Industry Term is added to a Company you replicate the said term using wp_set_object_terms() on the related Podcast (that you’ll retrieve using the bidirectional relationship from the Company). And vice-versa when a Industry Term is added for Podcast (if you want to).

    Hope it helps!

    Have a nice day.

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Bidirection Relationships With Custom Taxonomy’ is closed to new replies.