Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

You are trying to make the product ranking on the English page consistent with the product ranking on the Chinese page. The sorting is consistent on the homepage but varies when selecting a category to view products.

Solution:

To achieve consistent product order across languages, we recommend defining a secondary sorting condition. If sorting by SKU is your preferred method, you can add a custom code snippet to your theme's

 functions.php

file. Here is the code you need:

function custom_modify_shop_query($query) {
    // Only modify the shop order if an order has not been specified
    //if ( !isset($_GET['orderby']) && !is_admin() && $query->is_main_query() && is_shop()) {
    if (       
        !is_admin() &&
        $query->is_main_query() &&
        (is_shop() || is_product_category() || is_product_tag())
        ) {     
   
         // Set meta_key so SKU ordering works
         $query->set('meta_key', '_sku');
 
         // Set orderby to array: first by date, then by SKU
         $query->set('orderby', array(
             'date'       => 'DESC',
             'meta_value' => 'ASC',
         ));
     }
}

This code ensures that products are first sorted by date and then by SKU, applying across shop, category, and tag pages. Please check your staging site to confirm the sorting behaves as expected.

If this solution does not resolve your issue or seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.

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.

This topic contains 18 replies, has 2 voices.

Last updated by Bigul 3 weeks, 4 days ago.

Assisted by: Bigul.

Author Posts
June 12, 2025 at 2:27 am #17128190

edmondC-2

Also, when choosing to sort by price, it is also inconsistent. Could you please use SKU as the second sorting option? Can you write a SKU as the second sorting option for all sorting selections, so that it can take effect in any category or sorting selection

4.png
3.png
June 12, 2025 at 7:43 am #17128705

Bigul
WPML Supporter since 01/2013

Languages: English (English )

Timezone: Europe/Vienna (GMT+02:00)

Hello,

Please check the staging site now. The product category pages are showing the expected results, including when sorting is applied. This was achieved after making the following changes to the code.

function custom_modify_shop_query($query) {
    // Only modify the shop order if an order has not been specified
    //if ( !isset($_GET['orderby']) && !is_admin() && $query->is_main_query() && is_shop()) {
	if (       
        !is_admin() &&
        $query->is_main_query() &&
        (is_shop() || is_product_category() || is_product_tag())
        ) { 	
  
         // Set meta_key so SKU ordering works
         $query->set('meta_key', '_sku');

         // Set orderby to array: first by date, then by SKU
         $query->set('orderby', array(
             'date'       => 'DESC',
             'meta_value' => 'ASC',
         ));
     }
}

Refer to the following links for more details:

hidden link

hidden link

--
Thanks!

Bigul

June 12, 2025 at 9:20 am #17129181
edmondC-2

Hello, I have checked and there are still some inconsistencies. I have put out the product sorting options to see the effect;
Refer to the following links for more details:
hidden link

hidden link

June 12, 2025 at 6:22 pm #17131234

Bigul
WPML Supporter since 01/2013

Languages: English (English )

Timezone: Europe/Vienna (GMT+02:00)

Hello,

Thank you for the updates. I have created a new ticket for the price sorting issue to ensure easier follow-up, as it differs slightly from the original issue. We will get back to you as soon as possible via the new ticket. Please wait.

--
Thanks!

Bigul