Created
October 18, 2015 21:43
-
-
Save davidperezgar/bc7732c665812e71ba4a to your computer and use it in GitHub Desktop.
Wordpress Search Order by date not relevance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Imported from https://wordpress.org/support/topic/371-i-need-search-to-show-results-by-date-not-relevance | |
function my_search_query( $query ) { | |
// not an admin page and is the main query | |
if ( !is_admin() && $query->is_main_query() ) { | |
if ( is_search() ) { | |
$query->set( 'orderby', 'date' ); | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'my_search_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment