Support

Account

Home Forums General Issues How to auto select ACF relationship field based on taxonomy selection

Solving

How to auto select ACF relationship field based on taxonomy selection

  • Hello Guys,

    I have recently moved away from Joomla and starting using WP because of ACF. I think it is great.

    Currently I am working on a project where we have custom taxonomy called ‘Authors’, but we have decided to removed it and use custom post type instead. So, I have created a new custom post type called ‘Journal Authors’ and converted all of the taxonomy ‘Authors’ into the new custom post type.

    In ACF I have created a ‘relationship’ field type and filtered by this new ‘Journal Authors’ custom post type and applied it to the Posts.

    Now, my question is how can I automatically select the ACF ‘Journal Authors’ based on the ‘Authors’ taxonomy selection? We don’t want to open each post and select manually.

    I hope my explanation make sense. Please see the screenshots.

    I would be very grateful if you could please provide little help.

    Many Thanks
    Karen

  • I Just need little help/direction on how to select the ACF relationship field selections automatically based on the existing taxonomy selections. Any existing example maybe I could follow??

    Thank you
    Karen

  • The only way that you can do this is if there is some connection between the old taxonomy and the new post type.

    If this connection exists or if there is some data in each that can be relied on that can be used, for example if you can guarantee that post slug and the term slug will match. Otherwise you may need to add a taxonomy field to the new post type to select the old taxonomy so that you have some kind of a connection.

    If this connection can be made then I would create an acf/load_value filter for the relationship field. In this filter, if the value is empty then I would get the value of the old taxonomy field, get the posts related to that term and populated the value of the relationship field with the array of IDs that this returns.

  • Hi John,

    Thank you for your reply. I will look into the acf/load_value filter see if I can make it work.

    I was wondering if it might be easier to use WP All Import plugin to export the old taxonomy selections and then import it into the ACF relationship filed.

    regards
    Karen

  • Taxonomy fields contain Term IDs and Relationship fields use Post IDs. They are not interchangeable. There would still need to be some means to connect one with the other.

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

You must be logged in to reply to this topic.