0
votes

I have a WooCommerce store setup using the standard WordPress search feature. When I manually set the product order, it works for all of the category pages. However, if I do an empty search and return all the products, it doesn't sort by my product menu order in the search results.

Is there any way to add this in functions.php?

1

1 Answers

1
votes

I figured it out, I added the following to my functions.php file:

// CHANGE SORT BY FOR SEARCH

add_action('pre_get_posts','sortby_menuorder_query');

function sortby_menuorder_query($query) {
    if ( isset($_REQUEST['s']) ) {
        $query->set('orderby', 'menu_order');
        $query->set('order', 'ASC');
    }
}