Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created September 13, 2017 17:47
Show Gist options
  • Save Garconis/f7400f7981297a93b6c9758a9352292b to your computer and use it in GitHub Desktop.
Save Garconis/f7400f7981297a93b6c9758a9352292b to your computer and use it in GitHub Desktop.
WordPress | Force search results to be in alphabetical order
<?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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment