WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running WooCommerce and am trying to get the default product display to be sorted by the sku field in ascending order. So far I've come up with this:

/* Order products by SKU */
function reorder_products_by_sku( $query ) {
if(is_shop() && ! is_admin() && $query->is_main_query()) {
    $query->set('orderby', 'meta_value_num');
    $query->set('meta_key', 'sku');
    $query->set('order', 'ASC');
add_action( 'pre_get_posts', 'reorder_products_by_sku' );

This just tells me there are no products found which match my selection. Can anyone point me towards what I'm doing wrong?


share|improve this question
up vote 0 down vote accepted

You might want to take a look at the WooCommerce docs, there's a good snippet there showing now to add custom sort orders.

The link is http://wcdocs.woothemes.com/snippets/custom-sorting-options-ascdesc/

Once you've 'defined' your custom order you'll of course need to set it as the default in the store settings.

share|improve this answer
Thanks so much. That's extremely helpful :) – GusRuss89 Nov 9 '12 at 1:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.