Support

Account

Home Forums Add-ons Repeater Field Clone sub field values from relationship post

Unread

Clone sub field values from relationship post

    • jcb1125

    • October 30, 2020 at 7:15 am

    I found this topic from 2019 which was solved. But was trying to make this work with sub fields. i.e. – What if the Events fields were repeater fields that could be populated multiple Places fields (Map/Address fields, etc.). I gave it a shot below, but I’m missing something.

    https://support.advancedcustomfields.com/forums/topic/clone-field-value-from-relationship-post/#post-135706

    add_action('acf/save_post', 'save_event_update_address', 20);
    function save_event_update_address($post_id) {
      if (get_post_type($post_id) != 'events') {
        // not and event post, bail
        return;
      }
      // get location post ID
      // you said it's a relationship field, a relationship field will turn an array of posts
      // I am setting the 3rd parameter because we only need the IDs
      $related_places = get_sub_field('relationship_field_name');
      // also the 
      if ($related_places) {
        $place_id = $related_places[0];
        $address = get_field('address_field_on_place_name', $place_id);
        update_sub_field('address_field_on_event_repeater_name, $address, $post_id);
      }
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.