Search results page – why don’t filters work?

This topic has 4 replies, 2 voices, and was last updated 2 months, 2 weeks ago ago by Andrew Mitchell

  • Avatar: Niddy
    Niddy
    Participant
    September 18, 2025 at 15:15

    Hi

    Just wondering why the default shop filters don’t work on a search results page even though search is set to only show products (as we don’t use a blog and only have a shop / terms / privacy etc).

    When a shop like ours, with over 40,000 products uses search it can still load 500+ products in the results and thus the shop filters would be ideal.

    I’m aware it’s not a shop archive but surely we must be able to set custom filters or something to the results page?

    I’m specifically talking search results so like:
    /?s=MySearchTerm&post_type=only_product

    Also it is possible to change the default Sort by option from Relevance to Alphabetical (A-Z) on the search results page only – not the shop page (left as default).

    Thanks

    3 Answers
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 19, 2025 at 10:19

    Hello, Niddy,

    Thank you for reaching out to us and for providing detailed information regarding your inquiry.

    We understand the importance of having filtering options available on the search results page, particularly for stores with extensive product catalogs such as yours. Please note that, by default, the search results page is not treated as a standard WooCommerce shop or product archive page. As a result, the default shop filters do not appear or function as they typically would.

    That said, it is possible to implement custom solutions to enable filtering functionality on the search results page. For this, we kindly recommend contacting our customization service via the following link: https://www.8theme.com/contact-us/

    Regarding your request to change the default sorting option from “Relevance” to “Alphabetical (A–Z)” specifically on the search results page, this can also be achieved through custom coding. Please note that such modifications are not included in the standard support package.

    Should you have any further questions or require additional assistance, please do not hesitate to contact us.

    Best regards,
    The 8Theme Team

    Avatar: Niddy
    Niddy
    Participant
    September 19, 2025 at 10:45

    Hi

    I wouldn’t call this custom – surely you just allow the filters to work on non woo pages – certainly the search results page!

    As for sort options, again – it’s only not possible due to the way it’s been hard coded into your styling.

    Can you please clarify how you’re passing the relevance into the page? No hooks are working – example

    1. If passing relevance into the orderby then this should work (but does not)

    add_filter( 'woocommerce_get_catalog_ordering_args', 'xstore_replace_relevance_with_title', 20 );  // priority 20 or higher
    function xstore_replace_relevance_with_title( $args ) {
        // Only for search
        if ( is_search() && ! is_admin() ) {
            // Optionally check post_type or other param to ensure this is product search
            if ( isset( $_GET['orderby'] ) && $_GET['orderby'] === 'relevance' ) {
                $args['orderby'] = 'title';
                $args['order']   = 'ASC';
            }
            // Also handle case where no orderby is set
            if ( empty( $args['orderby'] ) ) {
                $args['orderby'] = 'title';
                $args['order'] = 'ASC';
            }
        }
        return $args;
    }

    2. If code resets order on load, then JS can be used to adjust the form before it’s submitted / before it sets the orderby like this but still, doesn’t work –

    document.addEventListener('DOMContentLoaded', function() {
        if ( document.body.classList.contains('search') ) {
            var select = document.querySelector('.woocommerce-ordering .orderby');
            if ( select && select.value === 'relevance' ) {
                select.value = 'title';  // change “title” to actual option value for alphabetical sort
            }
        }
    });

    Thanks.

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 22, 2025 at 06:58

    Hello, Niddy,

    1) Please try using the following code:

    add_action( 'pre_get_posts', function( $q ) {
        if ( is_admin() || ! $q->is_main_query() ) return;
    
        if ( $q->is_search() ) {
            $pt = $q->get( 'post_type' );
            if ( empty( $pt ) || 'product' === $pt ) {
                $q->set( 'orderby', 'title' );
                $q->set( 'order', 'ASC' );
            }
        }
    }, 20 );

    2) Note that the mentioned JavaScript will not work as expected, since it only changes the current value in the select element without actually triggering the selection. If you would like the new value to take effect, you need to use a trigger to initiate the select action after updating its value.

    Best regards,
    8Theme Team

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.