I have two CPT’s – “Resource” and “Publication”. Both share similar taxonomy’s, “Type” for example. “Publications” can be linked to “Resources” via an ACF relationship field using post objects.
Is there a way to add the taxonomy terms from the “Publications” to the “Resource” when the pubs posts are added via the relationship field? So the “Resource” would inherit all the “Types” from the pubs contained within, as it were?
I’m a little confuse about which way you want to add.
But you could
The above is simplified because you’d probably also want to deal with when relationships are removed or terms are updated on one site or the other. This can get complicated because you’d have to track both what the terms on each side were and what they are being changed to.
This isn’t something I’ve ever tried before, but it would mean having a priority of < 10 on the filter so that you can compare the current value of the relationship field with the previous value of the relationship field.
There is an example of doing this for biderectional relationship fields https://www.advancedcustomfields.com/resources/bidirectional-relationships/
But the problem is that you’re dealing with terms, so more than one relationship would be involved. The same terms could be added by other relationship fields.
So I would amend my previous steps. First off you would need to set up a bidirectional relationship field. You would also need to check all of the posts that are related to all of the posts in the relationship field 2 steps away
current post => relationship field => related posts relationship fields
to figure out what should be added/removed.
Thinking about it makes my head hurt a bit. I’m sure it’s possible but would take me several hours to work out the details.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.