Force Search Results To Be In Alphabetical Order

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

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


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' );

Need help?

Tell us about your project!

This field is for validation purposes and should be left unchanged.

Related articles