Created
January 27, 2018 22:25
-
-
Save gummiforweb/07e3cdf2389ced79b9b5406ce483ad29 to your computer and use it in GitHub Desktop.
ACF Gallery Field: Pull from default language's images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('acf/load_value/type=gallery', 'acf_load_translated_attachment_ids'); | |
function acf_load_translated_attachment_ids($value) { | |
// if the current language is the default language, | |
// then we don't need to fetch the translated ids | |
if (acf_get_setting('default_language') == acf_get_setting('current_language')) { | |
return $value; | |
} | |
// map throught each 'default language' id, and return the translated one | |
return array_map(function($id) { | |
return apply_filters('wpml_object_id', $id, 'attachment'); | |
}, $value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment