WPML
ステータス
開発者からの返答待ち
関連するプラグイン/テーマ
WP Grid Builder
トピックタグ
Compatibility

問題の概要

Grid BuilderWPMLおよびAdvanced Custom Fields (ACF)と併用すると、カスタムフィールドを使用するFacetsに問題が発生します。バックエンドでACFフィールドのラベルが翻訳されていても、フロントエンドには反映されません。

回避策

続行する前に、必ずサイトの完全なバックアップを作成してください。

Selectフィールドの場合


  • テーマのfunctions.phpファイルを開きます。

  • 次のコードを追加します。
    // 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 );
  • 元の言語でファセットが含まれるページにアクセスし、文字列を登録します。
  • WPML > 文字列翻訳ページに移動し、文字列を翻訳します。

注意: ファセットの構築方法によっては、以下のスニペットが役立つ場合があります。

// 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 );

すべての既知の問題 →