Support

Account

Home Forums General Issues Can I sync ACF fields AND values using local JSON? Reply To: Can I sync ACF fields AND values using local JSON?

  • What that does is just use a default. What you want to do is use a value from a different site if not set on the current site.

    What I would do it create an acf/load_value filter for each field, you may be able to use a single filter for multiple fields. You can even use this to update the value that are missing.

    
    // example for text field
    $text_fields = array(
      // list of field keys
      'field_1234',
      'field_4321'
    );
    foreach ($text_fields as $key) {
      add_filter('acf/load_field/key='.$key, 'load_text_field_from_master_site', 20, 3);
    }
    function load_text_field_from_master_site($value, $post_id, $field) {
      if ($post_id != 'options') { // or your appropriate ID
        // only for an options page
        return $value;
      }
      if (!empty($value)) {
        // field has a value
        return $value;
      }
      
      // get value from master site
      switch_to_blog(1); // or the ID of your master site
      $value = get_field($field['name'], $post_id);
      restore_current_blog();
      
      // update value on current site
      update_field($field['key', $value, $post_id);
    
      // return the value
      return $value;
    }