This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Tagged: Compatibility
This topic contains 11 replies, has 2 voices.
Last updated by mushehovO 1 year, 9 months ago.
Assisted by: Bruno Kos.
Author | Posts |
---|---|
February 21, 2023 at 3:47 pm #13080821 | |
mushehovO |
hello, need help. There are already many products and translated content. How to copy the main category (Rank Math Breadcrumbs (Make term primary)) into the translated content, so that the new translation would also take the main category from the main language. Thank you. |
February 22, 2023 at 2:51 pm #13090131 | |
Bruno Kos Supporter
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+01:00) |
Hi, Thank you for contacting WPML support! Can you send me few screenshots to illustrate which option are you referring to? Regards, |
February 22, 2023 at 3:32 pm #13090415 | |
mushehovO |
Hello |
February 23, 2023 at 7:21 am #13095075 | |
Bruno Kos Supporter
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+01:00) |
Hi, I see - it seems like that we have a case where primary category is not copied to translated posts at all. However we have a workaround until this is permanently fixed. 1) Under WPML > Settings > Custom Fields translate the following fields to "copy": rank_math_primary_category rank_math_primary_product_cat 2) Add the following code to your theme's functions.php: // 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; } https://wpml.org/de/forums/topic/split-rankmath-feature/#post-12864647 After this you can either open original post and click update so that the new setting takes effect, or you can try with bulk update like this hidden link. Regards, |
February 23, 2023 at 12:00 pm #13098455 | |
mushehovO |
Thanks for the answer. Unfortunately the code does not work correctly. After updating the product, the category changes, but not to the main one. This is the case with a product where there are 5 categories and one of them is the main one. Haven't tried other options. |
February 23, 2023 at 12:05 pm #13098497 | |
Bruno Kos Supporter
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+01:00) |
Hi, After updating the product, the category changes, but not to the main one. Can you perhaps send me some screenshots to illustrate where does this fail? Or a video recorded using tool such as hidden link? Regards, |
February 23, 2023 at 12:26 pm #13098681 | |
mushehovO |
I can make a video, but it must not be public |
February 23, 2023 at 12:43 pm #13098891 | |
Bruno Kos Supporter
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+01:00) |
Hi, The video URL will not be public - it will be hidden from everyone apart from you and members of WPML support team. You can confirm this if you check https://wpml.org/forums/topic/rank-math-breadcrumbs-make-term-primary/#post-13098497, you can see that it will show "Or a video recorded using tool such as hidden link?" Regards, |
February 23, 2023 at 1:13 pm #13099227 | |
mushehovO |
hidden link |
February 23, 2023 at 2:57 pm #13100817 | |
Bruno Kos Supporter
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+01:00) |
Hi, I am not sure I got it 100% - can you reproduce this here and send screenshots to illustrate the issue? but also use our code when trying to reproduce? Feel free to install and do whatever is needed on this website. Regards, |
February 23, 2023 at 3:25 pm #13101311 | |
mushehovO |
Let's try to explain without this tool. the first language, if you check the main category, in the second language, the category is shown according to woocommerce , where there is more than one category for the product, it displays the one above in the list. Rank Math allows you to choose the main category for the product, which is displayed in the breadcrumbs in a logical way. If you add your code and update the product, it does not set the main category. Breadcrumbs have changed, but not to the main category, but to a random one. The question is how to copy the checkmark of the main category of the first language to the second? |
February 23, 2023 at 3:33 pm #13101355 | |
mushehovO |
Okay, a thousand apologies. Everything works, I missed the moment of this step: Rank_Math_primary_category Rank_Math_primary_product_cat Thanks for the time given, everything works. My issue is resolved now. Thank you! |