• Resolved Beta2k

    (@beta2k)


    i use qtranslate x + advanced custom fields + ‘Advanced Custom Fields: qTranslate’.

    so i have multilanguage custom fields, i.e., 1 custom field, which i fill with two languages.

    my question is, can i somehow, when writing a page template in php use the german version custom field, if the englisch version is empty?

    i would expect something like this:
    if (get_field('description','en') == '') then echo (get_field('description','en')

    i know that get_field does not work like this, but this should be possible somehow? how?

    thanks!

    https://www.ads-software.com/plugins/qtranslate-x/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Beta2k

    (@beta2k)

    of course, in the second line of the posted pseudocode i would like to get the ‘german’ language of the field (because the ‘english’ is empty…

    This should do what you’re looking for.

    function qtrans_get_field($name, $lang = null) {
    	global $q_config;
    
    	// no language specified return in the
    	// current language
    	if ($lang === null) {
    		return get_field($name);
    	}
    
    	// switch to given language
    	$orig = $q_config['language'];
    	$q_config['language'] = $lang;
    
    	// retrive field value
    	$value = get_field($name);
    
    	// switch back to the original language
    	$q_config['language'] = $orig;
    
    	return $value;
    }
    Thread Starter Beta2k

    (@beta2k)

    where to put this? in my functions.php?

    Thread Starter Beta2k

    (@beta2k)

    okay i put this into functions.php

    it works! thank you very much. however, i can not check if the fieldvalue for one language is empty and then decide to take the other language, because when checking for empty value it will always return something. anyway, i just realized, that if the value for lanuage A is empty, i automatically get the value from the default language. so no need to check…

    hope this helps.

    Plugin Author Gunu

    (@grafcom)

    @beta2k,

    can we mark this topic as Resolved?

    Thread Starter Beta2k

    (@beta2k)

    yes, but how? i cant do it, i dont see the checkbox…

    Plugin Author Gunu

    (@grafcom)

    @beta2k,

    done… thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘get custom field in specific language’ is closed to new replies.