Skip to main content
How to Display the Search Results in Alphabetical Order

Learn how to configure your website to display search results alphabetically, improving user experience and content organization.

Updated over a week ago

Improving the way search results are displayed on your website can significantly enhance user experience and make it easier for visitors to find what they need.

Displaying search results in alphabetical order is one effective way to organize content, especially when dealing with large sets of data or products.

This article will guide you through the steps to configure your website to display search results alphabetically.

Change the search results display order using a child theme

  1. Install and activate a Child Theme for Divi

  2. Go to WordPress Dashboard β†’ Appearance β†’ Theme Files Editor

  3. Open the functions.php file and add this PHP snippet after the existing code:

    function divi_alphabetical_search_results ( $query ) {
    if( $query->is_search && !is_admin() ) {
    $query->set( 'orderby', 'title' );
    $query->set( 'order', 'ASC' );
    }
    }
    add_filter( 'pre_get_posts','divi_alphabetical_search_results' );

Change the search results display order without a child theme

  1. Install and activate the Code Snippets plugin

  2. Create a new PHP snippet and add this PHP snippet

    function divi_alphabetical_search_results ( $query ) {
    if( $query->is_search && !is_admin() ) {
    $query->set( 'orderby', 'title' );
    $query->set( 'order', 'ASC' );
    }
    }
    add_filter( 'pre_get_posts','divi_alphabetical_search_results' );

Note: Use only one of the two methods. If you don't want to or don't have a child theme, use the second method.

Did this answer your question?