Home Forums ACF PRO Sync two fields in different cpt


Sync two fields in different cpt

  • Hi,

    i have a field “notes” that i need to add to a Custom post type and to the user profile.
    Right now it’s working but what i need to do is synchronize both fields so if someone writes a note on the acf field on the user profile it automatically saves the content into the acf field on the custom post type and the reverse way too.

    Is it possible to sync both files?

  • This would be extremely difficult. How would you know what post to update in the CPT or what user to update when editing a post? What do these thinks have in common? How are they connected?

  • they are connected by user id
    That’s why i want the field in sync, so i can write a note on the user profile or in the cpt assignet to that user and the content need to be in sync

  • I’m thinking on using acf/save_post and create some kind of logic to update the field on both places at he same time…

  • I don’t understand the connection, but yes.

    use an acf/save_post action. Check the $post_id in this function to see if it is a user or a post that’s being updated. I would test to make sure it’s the right post type as well if it’s a post. Get value from the notes field that’s being updated, look up the other side, either the user or the post, and update the field for the other one. The biggest problem will be with updating posts. You’ll need to do a query to get a list of posts that match the user id and then loop through all of those posts and update the field for each one, even if that is only 1 post.

  • thk, john
    i’m doing it that way 😉

  • Can you share how to do that? i really need it too 🙂

    Thanks anyway.

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

The topic ‘Sync two fields in different cpt’ is closed to new replies.