Support

Account

Home Forums ACF PRO Clone field value from Relationship post Reply To: Clone field value from Relationship post

  • 
    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_field('relationship_field_name', $post_id, false);
      if ($related_places) {
        $place_id = $related_places[0];
        $address = get_field('address_field_on_place_name', $place_id);
        update_field('address_field_on_event_name', $address, $post_id);
      }
    }