Support

Account

Home Forums General Issues Multisite: Get field from main blog Reply To: Multisite: Get field from main blog

  • You should always return something, you will get an error if you don’t always return the array with all of the correct indexes unless you check for the existence of those indexes before you try to use them, but I wouldn’t worry about some of your checking for MS if you’re sure that it is a multisite setup.

    
    // Get custom fields from main blog
    function get_tracking_options() {
    	if (get_current_blog_id() != 1) {
    		switch_to_blog(1);
    	}
    	$custom_fields = array(
    		'head' 		=> get_field('tracking_head', 'options'),
    		'body' 		=> get_field('tracking_body', 'options'),
    		'footer' 	=> get_field('tracking_footer', 'options'),
    		'menu_html' => get_field('menu_html', 'options')
    	);
    	if (ms_is_switched()) {
    		restore_current_blog();
    	}
    	return $custom_fields;
    }