- Statut
- Résolu
- Signalé pour
- WPML SEO 2.1.0
- Résolu dans
- 2.2.0
- Extension/thème associé
- Rank Math SEO
- Étiquettes de sujet
- Compatibility
Aperçu de l’anomalie
Lors de l’utilisation de l’extension Rank Math SEO, la catégorie principale définie pour un produit ou un article dans la langue par défaut ne se synchronise pas avec ses traductions. Ce problème persiste même si vous définissez le champ personnalisé rank_math_primary_product_cat sur Copier.
Solution de contournement
Assurez-vous d’avoir une sauvegarde complète de votre site avant de continuer.
- Ouvrez le fichier functions.php du thème.
- Ajoutez le code suivant :
// compsupp-6580: sync primary term and primary product terms for Rank Math add_filter('get_post_metadata', 'compsupp6580_filter_the_post_metadata', 20, 4); function compsupp6580_filter_the_post_metadata($value, $postId, $key, $single) { $meta_keys_mapping = array( 'rank_math_primary_category' => 'category', 'rank_math_primary_product_cat' => 'product_cat', ); if (in_array($key, array_keys($meta_keys_mapping), true)) { remove_filter('get_post_metadata', 'compsupp6580_filter_the_post_metadata', 20); $value = get_post_meta($postId, $key, true); add_filter('get_post_metadata', 'compsupp6580_filter_the_post_metadata', 20, 4); $args = [ 'element_id' => $postId, 'element_type' => get_post_type($postId), ]; $language = apply_filters('wpml_element_language_code', false, $args); $value = apply_filters('wpml_object_id', $value, $meta_keys_mapping[$key], true, $language); if (!$single) { $value = [$value]; } } return $value; }