Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayeenulislam/965fa5ee36b96e6a677e to your computer and use it in GitHub Desktop.
Save mayeenulislam/965fa5ee36b96e6a677e to your computer and use it in GitHub Desktop.
WordPress - ascending or alphabetical order search result
<?php
/**
* Ascending order search result - WordPress
* @param object $query
* @return void
*/
function wp20150504_alphabetical_search_query( $query ) {
//checking whether we are in the search result page or not
if ( $query->is_search && $query->is_main_query() ) {
//setting/forching our desired order parameter o'er the default
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'wp20150504_alphabetical_search_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment