• Resolved beggers

    (@beggers)


    I have a big news site. People on my site search for the latest news so the fact that 3.7 changed the search results to “ordered by relevance” is a really bad thing for me. Search results are sometimes 2 years old which is useless – my users are reporting that Search is broken.

    How can I change the results back to “ordered by date”?

    This was really a big change and should have been an option, IMHO.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php

    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' );

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.

    Thread Starter beggers

    (@beggers)

    keesiemeijer, you are THE MAN!

    I’ll keep notes on this in case I upgrade because I haven’t figured out child themes yet.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘3.7.1 – I need search to show results by date not relevance’ is closed to new replies.