WP_Query question: Natural Sort Order for WooCommerce products
I am trying to achieve a natural sort order for the products in our store which have number references such as Nr.1, Nr.2, Nr.13 within the product title but WordPress/Woocommerce/WP_query whatever ends up sorting them Nr1., Nr.13, Nr.2. Due to my lacking programming skills, I am having a bit of a rough time with this:
Currently I am using the code here to sort ascending, alphabetically which works fine:
I thought this could be handled by adding a natsort function to the code above and I tried doing that without success, but I guess I was wrong.
I tried "Otto’s faked natural sorting solution" from here below unfortunately also without success:
WP Query orderby meta key natural sort?
I also found this post below but the link to the code snippet in the post is broken:
Sorting Woocommerce products with numeric titles
There is an older plugin called Woocommerce natural sort. Unfortunately its not working for me either.
I am puzzled as to what to do next. I wasn’t expecting this sorting thing to turn out this tricky. Does anybody have any alternative suggestions or maybe even a SQL query which I can execute directly via phpmyadmin?
Wouldn’t it be faster to sort the products directly in the db rather than running a query everytime?
Thanks in advance for your input! Much appreciated.