Title: Change default language mid-function
Last modified: March 4, 2023

---

# Change default language mid-function

 *  Resolved [arathra](https://wordpress.org/support/users/arathra/)
 * (@arathra)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/change-default-language-mid-function/)
 * In the middle of a function, I need to change the language in which WPGlobus 
   is working in. At the moment
 *     ```wp-block-code
       while( have_rows( 'countries_additional_option', 'option' ) ) {
   
       	the_row();
       	$value = get_sub_field( 'value' );
       	$label = get_sub_field( 'label' );
       }
       ```
   
 * The label always returns in the language the site is currently in. However, I
   wish to return it in a different language.
 * AI suggested wpglobus_switch_language( ‘it’ ) but that function doesn’t seem 
   to exist.
 * So how can I temporarily swap languages in the middle of a function?

Viewing 1 replies (of 1 total)

 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/change-default-language-mid-function/#post-16539154)
 * Here is the code
 *     ```wp-block-code
       /**
        * Get the multilingual value of the acf option.
        */
       function wpglobus_acf_get_sub_field($key, $order = 0) {
   
       	static $options = null;
       	if ( is_null($options) ) {
       		$options = acf_get_option_meta('options');
       		if ( ! is_array( $options ) ) {
       			return false;
       		}
       	}
   
       	$response = false;
   
       	foreach( $options as $option_key=>$option_value ) {
   
       		if ( $option_key[0] === '_' ) {
       			continue;
       		}
   
       		$_key = '_' . $order . '_' . $key;
   
       		if ( false === strpos($option_key, $_key) ) {
       			continue;
       		}
   
       		if ( ! empty( $option_value[0] ) ) {
       			$response = $option_value[0];
       		}
   
       	}
   
       	return $response;
       }
   
       $i = 0;
       while( have_rows( 'countries_additional_option', 'option' ) ) {
   
       	the_row();
   
       	// Get $value and $label in current lanuage.
       	// $value = get_sub_field( 'value' );
       	// $label = get_sub_field( 'label' );
   
       	// Get multilingual $value.
       	$value = wpglobus_acf_get_sub_field('value', $i);
       	// Get multilingual $label.
       	$label = wpglobus_acf_get_sub_field('label', $i);
   
       	// For example: Get $value in Italian.
       	$value = WPGlobus_Core::text_filter( $value, 'it' );
       	// For example: Get $label in Italian.
       	$label = WPGlobus_Core::text_filter( $label, 'it' );
   
       	$i++;
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Change default language mid-function’ is closed to new replies.

 * ![](https://ps.w.org/wpglobus/assets/icon-256x256.png?rev=1069705)
 * [WPGlobus](https://wordpress.org/plugins/wpglobus/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpglobus/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpglobus/)
 * [Active Topics](https://wordpress.org/support/plugin/wpglobus/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpglobus/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpglobus/reviews/)

## Tags

 * [switch](https://wordpress.org/support/topic-tag/switch/)

 * 1 reply
 * 2 participants
 * Last reply from: [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/change-default-language-mid-function/#post-16539154)
 * Status: resolved