Support

Account

Home Forums Front-end Issues Select2 not pulling saved values on MultiSite

Solved

Select2 not pulling saved values on MultiSite

  • I’ve got two select2 fields on a standard wp page in the admin. The first is a taxonomy field and the second is a post object. I’ve created a solution using the query hooks and JS API that dynamically filters the post object field based on what is selected in the taxonomy field. The solution works perfectly on my root site within my multisite. It also MOSTLY works in the subsites, with one exception. The filtering works as expected and I’ve confirmed the values are getting saved correctly in the database. However, when the admin page reloads after a save, the select fields are empty and the jQuery select field has no options. On the root site (where this is working correctly), the jQuery object for these fields has one option, being whatever option was previously saved to the database. I need to understand what is populating this jQuery object and see if I can hook into it and fix it. Or perhaps I need someone to help me better understand why this is happening in general.

  • Without code this will be hard to help with. How are you generating the values for the select field?

  • Thanks John,

    I’m defining the fields in the php, which I will include below. The taxonomy list is generated from a taxonomy defined on the root site. On subsites, I use the query and results hooks to switch to the root site for the query then back to the originating site after the query. I can also include the php and js hooks I’m using. The fields in question are ‘peopletype_taxonomy_list` which filters ‘people_by_type’.

    		acf_add_local_field_group(array(
    			'key' => 'group_59d53ce54567f',
    			'title' => 'People Group',
    			'fields' => array(
    				array(
    					'key' => 'field_59dd3068b24e6',
    					'label' => 'Copy',
    					'name' => 'copy',
    					'type' => 'wysiwyg',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'default_value' => '',
    					'tabs' => 'all',
    					'toolbar' => 'full',
    					'media_upload' => 1,
    					'delay' => 0,
    				),
    				array(
    					'key' => 'field_5c27f7a668daf',
    					'label' => 'Add By Individual',
    					'name' => 'add_by_individual',
    					'type' => 'true_false',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'message' => '',
    					'default_value' => 0,
    					'ui' => 1,
    					'ui_on_text' => '',
    					'ui_off_text' => '',
    				),
    				array(
    					'key' => 'field_5c27f7d868db0',
    					'label' => 'Add By People Type',
    					'name' => 'add_by_people_type',
    					'type' => 'true_false',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'message' => '',
    					'default_value' => 0,
    					'ui' => 1,
    					'ui_on_text' => '',
    					'ui_off_text' => '',
    				),
    				array(
    					'key' => 'field_5c27f7eb68db1',
    					'label' => 'Add By Site',
    					'name' => 'add_by_site',
    					'type' => 'true_false',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'message' => '',
    					'default_value' => 0,
    					'ui' => 1,
    					'ui_on_text' => '',
    					'ui_off_text' => '',
    				),
    				array(
    					'key' => 'field_59d53cee6770e',
    					'label' => 'People as Individuals',
    					'name' => 'people_as_individuals',
    					'type' => 'repeater',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array(
    						array(
    							array(
    								'field' => 'field_5c27f7a668daf',
    								'operator' => '==',
    								'value' => '1',
    							),
    						),
    					),
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'collapsed' => '',
    					'min' => 0,
    					'max' => 0,
    					'layout' => 'table',
    					'button_label' => '',
    					'sub_fields' => array(
    						array(
    							'key' => 'field_59d53d266770f',
    							'label' => 'Person',
    							'name' => 'person',
    							'type' => 'post_object',
    							'instructions' => '',
    							'required' => 0,
    							'conditional_logic' => 0,
    							'wrapper' => array(
    								'width' => '',
    								'class' => '',
    								'id' => '',
    							),
    							'post_type' => array(
    								0 => 'furman-person',
    							),
    							'taxonomy' => '',
    							'allow_null' => 0,
    							'multiple' => 0,
    							'return_format' => 'object',
    							'ui' => 1,
    						),
    					),
    				),
    				array(
    					'key' => 'field_5c2d0d1860d0f',
    					'label' => 'Select People Type',
    					'name' => 'peopletype_taxonomy_list',
    					'type' => 'taxonomy',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array(
    						array(
    							array(
    								'field' => 'field_5c27f7d868db0',
    								'operator' => '==',
    								'value' => '1',
    							),
    						),
    					),
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'taxonomy' => 'furman-person-type',
    					'field_type' => 'select',
    					'allow_null' => 0,
    					'add_term' => 1,
    					'save_terms' => 0,
    					'load_terms' => 0,
    					'return_format' => 'id',
    					'multiple' => 0,
    				),
    				array(
    					'key' => 'field_5c27fa0480c21',
    					'label' => 'People by Type',
    					'name' => 'people_by_type',
    					'type' => 'repeater',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array(
    						array(
    							array(
    								'field' => 'field_5c27f7d868db0',
    								'operator' => '==',
    								'value' => '1',
    							),
    							array(
    								'field' => 'field_5c2d0d1860d0f',
    								'operator' => '!=empty',
    							),
    						),
    					),
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'collapsed' => '',
    					'min' => 0,
    					'max' => 0,
    					'layout' => 'table',
    					'button_label' => '',
    					'sub_fields' => array(
    						array(
    							'key' => 'field_5c27fa0480c22',
    							'label' => 'Person',
    							'name' => 'person',
    							'type' => 'post_object',
    							'instructions' => '',
    							'required' => 0,
    							'conditional_logic' => 0,
    							'wrapper' => array(
    								'width' => '',
    								'class' => '',
    								'id' => '',
    							),
    							'post_type' => '',
    							'taxonomy' => '',
    							'allow_null' => 0,
    							'multiple' => 0,
    							'return_format' => 'object',
    							'ui' => 1,
    						),
    					),
    				),
    				array(
    					'key' => 'field_5c2d0d734763e',
    					'label' => 'Select Site',
    					'name' => 'site_taxonomy_list',
    					'type' => 'taxonomy',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array(
    						array(
    							array(
    								'field' => 'field_5c27f7eb68db1',
    								'operator' => '==',
    								'value' => '1',
    							),
    						),
    					),
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'taxonomy' => 'furman-site',
    					'field_type' => 'select',
    					'allow_null' => 0,
    					'add_term' => 1,
    					'save_terms' => 0,
    					'load_terms' => 0,
    					'return_format' => 'id',
    					'multiple' => 0,
    				),
    				array(
    					'key' => 'field_5c28136b1102f',
    					'label' => 'People by Site',
    					'name' => 'people_by_site',
    					'type' => 'repeater',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array(
    						array(
    							array(
    								'field' => 'field_5c27f7eb68db1',
    								'operator' => '==',
    								'value' => '1',
    							),
    							array(
    								'field' => 'field_5c2d0d734763e',
    								'operator' => '!=empty',
    							),
    						),
    					),
    					'wrapper' => array(
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'collapsed' => '',
    					'min' => 0,
    					'max' => 0,
    					'layout' => 'table',
    					'button_label' => '',
    					'sub_fields' => array(
    						array(
    							'key' => 'field_5c28136b11030',
    							'label' => 'Person',
    							'name' => 'person',
    							'type' => 'post_object',
    							'instructions' => '',
    							'required' => 0,
    							'conditional_logic' => 0,
    							'wrapper' => array(
    								'width' => '',
    								'class' => '',
    								'id' => '',
    							),
    							'post_type' => '',
    							'taxonomy' => '',
    							'allow_null' => 0,
    							'multiple' => 0,
    							'return_format' => 'object',
    							'ui' => 1,
    						),
    					),
    				),
    			),
    			'location' => array(
    				array(
    					array(
    						'param' => 'post_type',
    						'operator' => '==',
    						'value' => 'post',
    					),
    				),
    			),
    			'menu_order' => 0,
    			'position' => 'normal',
    			'style' => 'default',
    			'label_placement' => 'top',
    			'instruction_placement' => 'label',
    			'hide_on_screen' => '',
    			'active' => 1,
    			'description' => '',
    		));

    Here are the hooks being used.

    /*
     * Action hooks to modify query arguments within the People Group module
     */
    
    /*
     * Sets query args for Individual People Field
     */
    function individualPeopleQuery( $args, $field, $post_id ) {
    	$args['post_type'] = \Furman\PostTypes\People::POST_TYPE;
    
    	return $args;
    
    }
    
    add_filter('acf/fields/post_object/query/key=field_59d53d266770f', 'individualPeopleQuery', 10, 3);
    
    /*
     * Ensures that the title is correct when querying from child sites
     */
    function individualPeopleResult( $title, $post ) {
    	if ( strpos( $title, 'no title' ) ) {
    		$title = $post->post_title;
    	}
    
    	return $title;
    }
    
    add_filter('acf/fields/post_object/result/key=field_59d53d266770f', 'individualPeopleResult', 10, 3);
    
    function peopleTypeTaxonomyQuery( $args, $field, $post_id ) {
    	if ( ! Site::isRoot() ) {
    		$currentSite = get_current_blog_id();
    		switch_to_blog( Site::getRootBlogId() );
    		set_transient( 'peopleTypeTaxonomyQuery', $currentSite );
    	}
    
    	return $args;
    }
    
    add_filter('acf/fields/taxonomy/query/key=field_5c2d0d1860d0f', 'peopleTypeTaxonomyQuery', 10, 3);
    
    function peopleTypeTaxonomyResult( $title ) {
    	$originatingSite = get_transient( 'peopleTypeTaxonomyQuery' );
    	if ( Site::isRoot() && $originatingSite ) {
    		delete_transient( 'peopleTypeTaxonomyQuery' );
    		switch_to_blog( $originatingSite );
    	}
    
    	return $title;
    }
    
    add_filter('acf/fields/taxonomy/result/key=field_5c2d0d1860d0f', 'peopleTypeTaxonomyResult', 10, 3);
    
    //add_filter('acf/load_field/key=field_5c2d0d1860d0f', 'peopleType');
    
    /*
     * Set up custom query args received from AJAX requests.
     */
    function peopleByTypeQuery( $args, $field, $post_id ) {
    
    	if ( ! Site::isRoot() ) {
    		$currentSite = get_current_blog_id();
    		switch_to_blog( Site::getRootBlogId() );
    		set_transient( 'peopleByTypeQuery', $currentSite );
    	}
    
    	$args['post_type'] = \Furman\PostTypes\People::POST_TYPE;
    
    	if ( isset( $_POST['query-args'] ) ) {
    		$termId = $_POST['query-args']['term_id'];
    		$args['tax_query'] = array(
    			array(
    				'taxonomy' => \Furman\Taxonomies\PeopleTypes::TAXONOMY,
    				'field' => 'term_id',
    				'terms' => $termId
    			)
    		);
    	}
    
    	return $args;
    
    }
    
    add_filter('acf/fields/post_object/query/key=field_5c27fa0480c22', 'peopleByTypeQuery', 10, 3);
    
    function peopleByTypeResult($title) {
    	$originatingSite = get_transient( 'peopleByTypeQuery' );
    	if ( Site::isRoot() && $originatingSite ) {
    		delete_transient( 'peopleByTypeQuery' );
    		switch_to_blog( $originatingSite );
    	}
    
    	return $title;
    }
    
    add_filter('acf/fields/post_object/result/key=field_5c27fa0480c22', 'peopleByTypeResult', 10, 3);
    
    function peopleSiteTaxonomyQuery( $args, $field, $post_id ) {
    	if ( ! Site::isRoot() ) {
    		$currentSite = get_current_blog_id();
    		switch_to_blog( Site::getRootBlogId() );
    		set_transient( 'peopleSiteTaxonomyQuery', $currentSite );
    	}
    
    	return $args;
    }
    
    add_filter('acf/fields/taxonomy/query/key=field_5c2d0d734763e', 'peopleSiteTaxonomyQuery', 10, 3);
    
    function peopleSiteTaxonomyResult( $title ) {
    	$originatingSite = get_transient( 'peopleSiteTaxonomyQuery' );
    	if ( Site::isRoot() && $originatingSite ) {
    		delete_transient( 'peopleSiteTaxonomyQuery' );
    		switch_to_blog( $originatingSite );
    	}
    
    	return $title;
    }
    
    add_filter('acf/fields/taxonomy/result/key=field_5c2d0d734763e', 'peopleSiteTaxonomyResult', 10, 3);
    
    function peopleBySiteQuery( $args, $field, $post_id ) {
    
    	if ( ! Site::isRoot() ) {
    		$currentSite = get_current_blog_id();
    		switch_to_blog( Site::getRootBlogId() );
    		set_transient( 'peopleBySiteQuery', $currentSite );
    	}
    
    	$args['post_type'] = \Furman\PostTypes\People::POST_TYPE;
    
    	if ( isset( $_POST['query-args'] ) ) {
    		$termId = $_POST['query-args']['term_id'];
    		$args['tax_query'] = array(
    			array(
    				'taxonomy' => \Furman\Taxonomies\Sites::TAXONOMY,
    				'field' => 'term_id',
    				'terms' => $termId
    			)
    		);
    	}
    
    	return $args;
    
    }
    
    add_filter('acf/fields/post_object/query/key=field_5c28136b11030', 'peopleBySiteQuery', 10, 3);
    
    function peopleBySiteResult($title) {
    	$originatingSite = get_transient( 'peopleBySiteQuery' );
    	if ( Site::isRoot() && $originatingSite ) {
    		delete_transient( 'peopleBySiteQuery' );
    		switch_to_blog( $originatingSite );
    	}
    
    	return $title;
    }
    
    add_filter('acf/fields/post_object/result/key=field_5c27fa0480c22', 'peopleBySiteResult', 10, 3);

    Here are the JS API hooks in use

    document.addEventListener('DOMContentLoaded', () => {
    
        acf.add_action('select2_init', function( $select, args, settings, field ){
            console.log('SELECT2_SELECT:', $select);
            console.log('SELECT2_ARGS:', args);
            console.log('SELECT2_SETTINGS:', settings);
            console.log('SELECT2_FIELD:', field);
            // $select (jQuery) select element
            // args (object) args given to the select2 function
            // settings (object) settings given to the acf.select2 function
            // field (object) field instance
        });
        /*
        Uses the ACF JS API.  These filters allow the post object fields to be filtered based on a separate acf taxonomy field.
         */
        acf.add_filter('select2_ajax_data', function (data, args, $input, field, instance) {
            //People Type filter
            if (field[0].dataset.key === 'field_5c27fa0480c22') {
                let taxonomySelect = $('.acf-field-5c2d0d1860d0f').find('.select2-hidden-accessible').select2('data');
                data['query-args'] = {
                    'taxonomy': 'furman-person-type',
                    'term_id': taxonomySelect[0].id,
                    'term_title': taxonomySelect[0].text
                };
            }
            //Site filter
            if (field[0].dataset.key === 'field_5c28136b11030') {
                let taxonomySelect = $('.acf-field-5c2d0d734763e').find('.select2-hidden-accessible').select2('data');
                data['query-args'] = {
                    'taxonomy': 'furman-site',
                    'term_id': taxonomySelect[0].id,
                    'term_title': taxonomySelect[0].text
                };
            }
    
            // return
            return data;
    
        });
    
    });
  • Here’s some more info I’ve found. So to my knowledge the php hook that occurs right before field render is acf/prepare_field. Dumping the field shows that the value is present. Now the big question is, why isn’t it making it into the select2 jQuery object, and what handles the creation of that piece?

    array (size=31)
      'ID' => int 0
      'key' => string 'field_59e61ff30ff19_field_5c2d0d1860d0f' (length=39)
      'label' => string 'Select People Type' (length=18)
      'name' => string 'acf[field_5953fae740968][0][field_59e61ff30ff19_field_5c2d0d1860d0f]' (length=68)
      'prefix' => string 'acf[field_5953fae740968][0]' (length=27)
      'type' => string 'taxonomy' (length=8)
      'value' => int 123
      'menu_order' => int 5
      'instructions' => string '' (length=0)
      'required' => int 0
      'id' => string '' (length=0)
      'class' => string '' (length=0)
      'conditional_logic' => 
        array (size=1)
          0 => 
            array (size=1)
              0 => 
                array (size=3)
                  ...
      'parent' => string 'field_5953fae740968' (length=19)
      'wrapper' => 
        array (size=3)
          'width' => string '' (length=0)
          'class' => string '' (length=0)
          'id' => string '' (length=0)
      '_name' => string 'peopletype_taxonomy_list' (length=24)
      '_prepare' => int 1
      '_valid' => int 1
      'taxonomy' => string 'furman-person-type' (length=18)
      'field_type' => string 'select' (length=6)
      'allow_null' => int 0
      'add_term' => int 1
      'save_terms' => int 0
      'load_terms' => int 0
      'return_format' => string 'id' (length=2)
      'multiple' => int 0
      '_clone' => string 'field_59e61ff30ff19' (length=19)
      'parent_layout' => string '59e61fe0a4879' (length=13)
      '__key' => string 'field_5c2d0d1860d0f' (length=19)
      '__name' => string 'peopletype_taxonomy_list' (length=24)
      '__label' => string 'Select People Type' (length=18)
  • I think you just shot over my ability to help you here, but I will give it a go.

    I suspect that it is something to do with getting values from the root site and switching sites…… but I’m not sure

    Another guess is that it may have something to do with the taxonomy/term not existing on the sub site. When ACF attempts to get the term/value for the current post it’s not finding any and the result is that the value is cleared in the admin, but I cannot be sure. I really suspect that this is the case, ACF does not know what to set the value to when the page is loaded. If this is the case, I’m not sure there is a way to fix it. You might be able to use the acf/load_value hook to attempt to…

    You’ll have to excuse the rambling of this post, I’m doing some digging through the code figure it out as I go.

    When ACF loads the value of the field it does

    
    $value = acf_get_valid_terms($value, $field['taxonomy']);
    

    This reads through all the terms that have been set to see if it’s a valid term, if not they are removed. So this where you’re problem is.

    Going back to what I said, you may be able to correct this by adding an acf/load_value filter https://www.advancedcustomfields.com/resources/acf-load_value/. Set the priority > 10 so it runs after ACf and then reset the correct values. In your filter you will likely need to use get_post_meta() to get the current value of the field because you will need to completely bypass ACF in order to avoid ACF’s check for valid terms.

  • Hi John,

    Sorry I hit the problem solved button on accident. As a side question, do you know how the data for select2 fields is built and placed on the window object in the js? The jQuery objects are there with the data on page load but I don’t see any xhr data in devtools indicating an ajax request was made to populate those objects. So now my question is, how in the heck did the data get there?

  • I don’t know how the data is added to the page. I do know that the current value of the field is populated with PHP on the server. No requests are made until you interact with the field.

  • Thanks John that helps. I’m trying to override whatever code is preventing my taxonomy value from loading on subsites. To your knowledge, is prepare_field the closest thing to render that you can hook into? I’ve tried messing with that one and adjusting the priority higher and higher. However, the field value is present and correct no matter what I do. It’s super frustrating. The field value is there but the select option is never rendered.

  • Yes, prepare_field is probably the closes hook before it is rendered.

    I just had a look at the render_field function for the taxonomy field and found another place where there is likely an issue with the value not appearing.

    The render field function for the taxonomy field also cause ACF to check for valid terms. There are no hooks in the render field method of the field type that will let you filter this and show terms that do not exist on the current site.

    There are 2 options that I know of.

    The first would be to create your own field type based on the ACF taxonomy field and remove the code that tests the terms. https://www.advancedcustomfields.com/resources/creating-a-new-field-type/

    The second would be a bit of a hack and I don’t know if it will work.

    Use the acf/render_field hook hhttps://www.advancedcustomfields.com/resources/acf-render_field/. While it is undocumented on this page, this hook also includes the field name and field key variations that all of the other field hooks include.

    Use this hook to create 2 actions, one that is fired before ACF (priority < 10) and one that is fired after ACF (priority > 10). In the first hook, switch to the main site and in the second hook switch back to the current site.

  • John, thanks so much for all of your insight. I’ll look into these options.

  • Knowing what I know now, I would probably build something like this a different way, and I don’t know if you can make this change or not, but I thought I would suggest it. Dealing with using data from different sites in a multisite setup is always difficult.

    Anyway, this is what I would do.

    1) get rid of the taxonomy field
    2) Use a basic select field (or checkbox, radio field)
    3) Populate the choices of this field dynamically (term->term_id => term->term_name) https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    This solution lets you avoid the problems you’re facing with the taxonomy field.

  • I finally tracked down the issue and thought I’d post my findings. The hack option didn’t work. I’ll post the code I used and you can tell me if that’s what you were suggesting I try. So far as I can tell, the breakdown happens on line 643 of class-acf-field-taxonomy.php in the render_field_select function. $this->get_terms doesn’t return any terms on subsites. It looks like i’ll have to pursue creating my own field that modifies the taxonomy field.

    function switchBeforeRender( $field ) {
    
    	if ( ! Site::isRoot() ) {
    		$currentSite = get_current_blog_id();
    		switch_to_blog( Site::getRootBlogId() );
    		set_transient( 'switchBeforeRender', $currentSite );
    	}
    
    }
    add_action( 'acf/render_field/type=select', 'switchBeforeRender', 8, 1 );
    
    function switchAfterRender( $field ) {
    
    	$originatingSite = get_transient( 'switchBeforeRender' );
    	$currentSite     = get_current_blog_id();
    	if ( $currentSite === 1 && $originatingSite ) {
    		delete_transient( 'switchBeforeRender' );
    		switch_to_blog( $originatingSite );
    	}
    
    }
    add_action( 'acf/render_field/type=select', 'switchAfterRender', 15, 1 );
    
  • I just saw your most recent reply. I thought of using a basic select field and using load_field to setup the choices, but the client wants the fancy select2 field with the searchbar and ajax functionality, so I’m going to try to create my own field based on the taxonomy select2 field and fall back to the basic select if that’s not possible. If I can use the taxonomy select code as a template and just modify the term query I think I should be able to make it work.

  • I thought you were using a taxonomy field
    try using

    add_action( 'acf/render_field/key=field_5c2d0d1860d0f' ......

  • I am using a taxonomy field. I didn’t try that because the docs don’t say you can use key= on render_Field, it just shows type=. I tried that and it does fire correctly but still doesn’t fix the issue. Switching to the root site (and not switching back) allows the taxonomy field to work as expected, but once I add the later hook to switch back it goes back to not loading the field value.

  • As far as select vs taxonomy field, sometimes my clients don’t get everything they’re wishing for. Functioning is a higher priority than making it work and while I do my best to make the admin experience as nice as I can for them, making it work overrides making it pretty, and my clients don’t get much say in the design of the admin.

  • The documentation is a bit behind on the hooks, that’s why I mentioned them above.

  • I don’t disagree with you, and if this were my own client I’d have gone that route a long time ago. However, I’m an agency developer and I’m not the lead on this one. I can push back on my lead and communicate the difficulties, but I have a feeling it’s going to be the select2 or bust. It’s for a big university site, and this particular taxonomy will have many terms so the search will come in handy.

  • A custom field type is a good alternative, you can basically copy all of the code from the ACF field type and paste it directly into your custom field type definition and it should work, and then remove the parts that are causing the issues. I’ve done this a couple of times to add something I’ve needed.

  • This is the closest I’ve found to what I’ve been having happen.
    I’ve got two field groups that when they are both used on the same page, one fails to load its values in the editor.
    One is just a handful of fields that are used for a header on certain pages.
    The other is a system where I have records of people created on one site in the multisite that I can call and display on pages on other sites.
    Recently, when both of those field groups are used on the same page, the simple one fails. It seems to be because it is looking for the content on the other site where the people are called.
    to handle the switch to the other site to call up the people, I use this filter:

    function mhsl_acf_prepare_who( $field ) {
    	$this_site_id = get_current_blog_id();
    	switch_to_blog(5); // 5 is the id of the site where the people are stored
        return $field;
    	switch_to_blog($this_site_id); 
    }
    add_filter('acf/prepare_field/name=who', 'mhsl_acf_prepare_who', 99, 1); // I've tried various priority numbers

    I tried filtering the other fields to a higher priority too. No change.

  • John, I wanted to come back once again and thank you for your help. The custom field solution works well and will be a great tool for future endeavors I’m sure. Thanks for all the time you put in helping me get over the hump here.

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

The topic ‘Select2 not pulling saved values on MultiSite’ is closed to new replies.