Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nocean/9cda534f1d7abd2294d1702f0440c0c0 to your computer and use it in GitHub Desktop.
Save nocean/9cda534f1d7abd2294d1702f0440c0c0 to your computer and use it in GitHub Desktop.
How to get language independent ACF theme options on a WPML site
<?php
/**
* To get this to work, you need to tinker with the acf/settings/ filter and reset the default language
* so that the get_field() function returns the correct results even when not on the default language.
*
* You can add the filter before you call the get_field() function and then remove it once complete.
*
* answer courtesy of James of ACF Support + love on GitHub
*/
// Use this to stop ACF from trying to look for a language-specific version of fields.
add_filter('acf/settings/current_language', '__return_false');
// Insert your regular ACF code between the add_filter and remove_filter lines.
$my_field = get_field( 'my_field', 'option' );
// Use this to re-enable language-specific retrieval of ACF fields.
remove_filter('acf/settings/current_language', '__return_false');
@ip2C
Copy link

ip2C commented Aug 9, 2018

How can i include this in my loop?

`` $args = array(
'posts_per_page' => '999',
'post_type' => 'product',
'meta_key' => 'auszeichungen',
'meta_value' => '',
'meta_compare' => '!=',
'order' => 'DESC'
);

$awardsProducts = get_posts($args);

foreach($awardsProducts as $awardsProduct) {

	$innerawards = get_field('auszeichungen',$awardsProduct->ID, 'option');
 
	``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment