How to order WP_Query to group results?
-
I have a list of products in WooCommerce that have titles like so:
Please note: The “groups” are just for myself, they are not categories etc. All products are the same type of product, just two types of products have different codes (Z and UK)
“Group 1” – Unique numbers
- 5000
- 4999
- 4998
- 4997
- 4996
- etc etc
“Group 2” – Unique numbers that begin with a Z
- Z5000
- Z4999
- Z4998
- Z4997
- Z4996
- etc etc
“Group 3” – Unique numbers that begin with UK
- UK5000
- UK4999
- UK4998
- UK4997
- UK4996
- etc etc
Obviously by default, WordPress orders by date so on the product’s archive page, they look like this:
- UK4020
- 2122
- Z3122
- 4999
- UK1001
- etc etc
What I would like (but can’t seem to find any answer with my Google-fu), is to custom order my products like so:
- Unique numbers, in descending order
- Unique numbers that begin with Z, in descending order
- Unique numbers that begin with UK, in descending order
… So my products look like this:
- 5000,
- 4999,
- etc
- Z5000,
- Z4999,
- etc
- UK5000,
- UK4999
- etc
Hope the above makes sense!
- The topic ‘How to order WP_Query to group results?’ is closed to new replies.