Title: Set secondary sorting
Last modified: November 1, 2019

---

# Set secondary sorting

 *  Resolved [coholm](https://wordpress.org/support/users/coholm/)
 * (@coholm)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/set-secondary-sorting/)
 * I would like to alter the sorting of product results based on two fields.
    The“
   _sku” field and a custom field called “wpcf-serie”
 * Is there a way to add a filter to functions.php to achieve this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Sumit Singh](https://wordpress.org/support/users/5um17/)
 * (@5um17)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/set-secondary-sorting/#post-12088639)
 * Hi,
 * Sorry meta keys ordering is not available in the plugin feature yet. I would 
   consider this adding in future version.
 * As a workaround please select both keys in WPES setting then add the following
   code in functions.php and disable the ordering feature in WPES settings.
 *     ```
       add_action('pre_get_posts', 'wpes_support_topic_set_secondary_sorting', 501);
       function wpes_support_topic_set_secondary_sorting($query) {
           if (!empty($query->is_search)) {
       	$query->set( 'orderby', array(
       	    '_sku' => 'ASC',
       	    'wpcf-serie' => 'ASC'
       	));
           }
       }
       ```
   
 * This should work.
 * Thanks
    -  This reply was modified 6 years, 7 months ago by [Sumit Singh](https://wordpress.org/support/users/5um17/).
 *  Thread Starter [coholm](https://wordpress.org/support/users/coholm/)
 * (@coholm)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/set-secondary-sorting/#post-12093284)
 * Thank you so much. This worked perfectly.
 * (I also had to add the code from one of your previous replies to make _sku visible:
   [https://wordpress.org/support/topic/search-hidden-meta_keys-with-_underscore/](https://wordpress.org/support/topic/search-hidden-meta_keys-with-_underscore/))
    -  This reply was modified 6 years, 7 months ago by [coholm](https://wordpress.org/support/users/coholm/).
    -  This reply was modified 6 years, 7 months ago by [coholm](https://wordpress.org/support/users/coholm/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Set secondary sorting’ is closed to new replies.

 * ![](https://ps.w.org/wp-extended-search/assets/icon-256x256.png?rev=2436853)
 * [WP Extended Search](https://wordpress.org/plugins/wp-extended-search/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-extended-search/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-extended-search/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-extended-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-extended-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-extended-search/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [coholm](https://wordpress.org/support/users/coholm/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/set-secondary-sorting/#post-12093284)
 * Status: resolved