Hiding alternative content not working with ACF custom fields
Closed this issue · 1 comments
Hi everyone:
Im making a webpage with ACF, Advanced Custom Fields: qTranslate and qtranslate-x in english and spanish and i want to hide the content of some text fields if the text is not translated on the selected language. In the configuration of the qtranslate-x seems like there are two options that can manage this, but anyone of these makes any change if the content is on a custom field.
If the content is from a default field it works fine, shows a message saying that the content is not available in the selected language, but if i do the same with a custom field, like a text field in a ACF repeater, it shows something like: [English] xxxxxxxx, when i just want to hide the field completly.
PD: Plugins are up to date and Custom fields are Qtranslate text, not basic text.
Any help is appreciated,
Thanks, César.
Solved with #85 .
Here is the code that worked for me:
remove_filter('get_post_metadata', 'qtranxf_filter_postmeta', 5, 4);
remove_all_filters('acf/format_value');
add_filter('acf/format_value', function($value){
if (is_string($value)) {
$value = qtranxf_useCurrentLanguageIfNotFoundShowEmpty($value);
}
return $value;
});
This fix have a problem and it happens when you try to put a qtranslate image or something that need a url on qtranslate acf field, the_field() returns false.
So i created 3 normal ACF images and used qtrans_getlanguage function to get the correct.
<?php $lang = qtrans_getLanguage(); ?>
<?php if($lang == 'es'): ?>
<img src="<?php the_field('imagen_proceso_quees_espanol'); ?>" alt="">
<?php elseif($lang == 'en'): ?>
<img src="<?php the_field('imagen_proceso_quees_ingles'); ?>" alt="">
<?php endif; ?>