I have a Woo product archive template, sorted by custom field "Hmotnost" (weight). But as I have lots of products with same weight, I need secondary sorting by SKU to keep products sorting predictably, not randomly (therefore I need this secondary sorting).
Hello, Minesh,
thanks very much for your response, however, it still doesn't work as expected.
The primary sorting works fine (field wpcf-produkt-hmotnost), but the secondary sorting is still random - each time I reload the page, different order of results is displayed.
Tried to put the code first to functions.php of my child theme (Generate Press), then to Custom code snippets and same results in both cases. Shouldn't I change something in the archive template as well? I am using a select to sort results on the frontend - (weight and price - the weight/Hmotnost should be default sorting)
Thanks very much for your time
Tom
But I belive it will give you on sorting at a time. If you select "weight", it should sort by weight, if you select "SKU", it should sort result by SKU. Is this you want - I man as per the user's selected choice the sorting should be performed?
In addition to that - Can you please share problem URL of your archive as well as admin access details and tell me what is your expected results and how exactly you want to sort the product posts.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Hello, Minesh, first of all - thank you!
But there is a small "but" - it works almost as expected 🙂
Upon entry to the shop page, it orders the products by weight and then SKU, but it starts with weight "1.2441 g", completely ignoring products with "1 g" weight, which are ordered just after all weights with weight fraction starting with "1".
I think it is because of the delimiter, is that correct? I think I would be able to change the delimiter from "." to "," which is default to the rest of the web. As this is not a piece of cake operation in my situation - do you think this might cause the problem? If you think it is, I will change it, no problem 🙂 I just want to avoid not necessary work in case I am mistaken 🙂
Thank you VERY much!
Sorry, now it displays/orders the weight correctly, but the secondary sorting (SKU) is not working - the results are chaotic once again as in the start. The previous code was closer to desired 🙂 I don't want to waste your time - was the problem in the decimal delimiter? I can change it from "." to ","
I'm not sure otherwise code is correct to set order by result per weight and sku.
Maybe you can check with SQL query expert based on your content and check why you do not get the desired results. The result is not displaying as expected only when the SKU as secondary sortin applied.