• I recently upgraded our news site from WP 3.2 (yes, I know I’m slow… ) to WP 4.9.4.

    Since the update I’ve have found that search results – which formerly were in strictly descending order by post_date from the most recent news article back to the earliest – are now returning results that begin with a few very old news articles at the top, then a chronological list from oldest to earliest, and then some more old ones at the bottom.

    I had a look at WP_query in the Codex, then looked over class-wp-query.php in /wp-includes, then searched the forums to see if anyone else had brought this up.

    Is this a bug in 4.9.4? Or could there be some other cause? (I’ve tried deactivating my plugins but this appears to have had no effect)

    I’d appreciate any insights anyone can provide – thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    Thread Starter David123456

    (@david123456)

    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' );
    
    Thread Starter David123456

    (@david123456)

    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 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post_Date Search Results In WP 4.9.4’ is closed to new replies.