WordPress

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.

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

Need Help?

Tell us about your project!

  • Date Format: MM slash DD slash YYYY
  • This field is for validation purposes and should be left unchanged.

Related articles

Menu
Google Rating
5.0
Based on 58 reviews
×