Search was changed in 3.7 to sort by relevance. I don’t have the full details on me, but essentially it’s sorted by whether the search phrase is found in the title, excerpt or content.
Thank you very much Jacob
Personally, this is a bit of a bummer – as a news site, we want to display stories in chronological order (ie by post date, backwards in time) because it gives our readers a better experience.
So I guess my only option will be to hack class-wp-query.php to make post_date the dominant search results driver, then repeat the exercise every time there’s a core update.
Still, maybe a future release will give site operators the ability to choose what search criteria they want to be dominant (eg: relevance, post_date etc).
This would be a snappy improvement to make, though I expect there’d be some complex coding required … and class-wp-query.php is already a very long and complex routine.
All the same, very much appreciated 🙂
Personally, this is a bit of a bummer – as a news site, we want to display stories in chronological order (ie by post date, backwards in time) because it gives our readers a better experience.
I think I’d dispute this. I think in a search context people expect the most relevant search results first.
So I guess my only option will be to hack class-wp-query.php to make post_date the dominant search results driver, then repeat the exercise every time there’s a core update.
No. Don’t do this. Never edit core files. If you want to change the order of search results you can use the following function in your theme or plugin:
function my_search_order( $query ) {
if ( $query->is_main_query() && $query->is_search() ) {
$query->set( 'orderby', 'date' );
}
}
add_action( 'pre_get_posts', 'my_search_order' );
Thank you very much Jacob!
I agree with you that editing a core file is inadvisable and something I’ve always tried to avoid (so far, successfully – which is probably why our recent big leap upgrade went so smoothly)
Anyway, I’ll locate the search box function in my theme, try this and let you know how I get on.
Much appreciated 🙂