콘텐츠로 건너뛰기 사이드바로 건너뛰기

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using Grid Builder with WPML and Advanced Custom Fields (ACF), there’s a problem with Facets using custom fields. Even though the ACF field labels are translated in the backend, they are not reflected in the frontend.

Workaround

Please, make sure of having a full backup of your site before proceeding.

For Select fields

  • Open your theme’s functions.php file.
  • Add the following code:
    // WPML Workaround for wpmlsupp-11647
    function wpml_wpmlsupp11647_translate_facet_choices( $choices, $facet ) {
    
    	if ( class_exists('Sitepress') ) {
    		foreach ($choices as &$choice) {
    			$string = $choice->facet_name;
    			$textdomain = 'facets';
    			$string_name = 'Facet: '.substr($string, 0, 20);
    		
    			if ( apply_filters('wpml_default_language', NULL ) == apply_filters( 'wpml_current_language', NULL )) {
    				do_action( 'wpml_register_single_string', $textdomain, $string_name, $string );
    			}	
    			// Apply the translation to the string
    			$choice->facet_name = apply_filters('wpml_translate_single_string', $string , $textdomain, $string_name);
    		}
    	}
    
    	return $choices;
    
    }
    
    add_filter( 'wp_grid_builder/facet/choices', 'wpml_wpmlsupp11647_translate_facet_choices', 10, 2 );
    
  • Visit the page with the facets in the original language to register the strings.
  • Go to WPML > String Translation page and translate the strings.

Note: Depending on how your Facets were built, this other snippet may be helpful:

// WPML Workaround for compsupp-7453
function wpml_compsupp7453_translate_facet_block_custom_field( $output ) {
 
    if ( class_exists('Sitepress') ) {
        if( is_string($output) ) {

            $string = $output;
            $textdomain = 'facets';
            $string_name = 'Facet: '.substr($string, 0, 20);
         
            if ( apply_filters('wpml_default_language', NULL ) == apply_filters( 'wpml_current_language', NULL )) {
                do_action( 'wpml_register_single_string', $textdomain, $string_name, $string );
            }   
            // Apply the translation to the string
            $output = apply_filters('wpml_translate_single_string', $string , $textdomain, $string_name);
        }
    }
 
    return $output ;
 
}
 
add_filter( 'wp_grid_builder/block/custom_field', 'wpml_compsupp7453_translate_facet_block_custom_field', 99, 2 );

응답 2개 대상 “Grid Builder - Facets using ACF fields labels are not translated in frontend”

  1. I haven’t had any luck with this. Is anything in the code specific to the website? Do I need to make any changes?

    I was able to get Facets to register in the string translation, and I’ve translated them, but the facets still aren’t appearing on the front end.

답글 남기기

주제에 집중하고 다른 사람을 존중해 주세요. 이 게시물과 관련 없는 문제에 도움이 필요하면 지원 포럼을 사용하여 채팅을 시작하거나 티켓을 제출하세요.

다음 태그를 사용할 수 있습니다:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>