Force Search Results To Be In Alphabetical Order

WordPress

By default, WordPress organizes posts within search results based on the post date.

You can easily override this by changing the OrderBy to Title.

<?php

function abc_search( $query ) {
	if( $query->is_search && !is_admin() ) {
		$query->set( 'orderby', 'title' );
		$query->set( 'order', 'ASC' );
	}
}
add_filter( 'pre_get_posts','abc_search' );
Menu
Google Rating
5.0
Based on 247 reviews
×
Get a Quote