• Resolved Brian

    (@womensradio)


    Using v8.1.1 of “Search Everything” on our site https://www.womensradio.com and have been a very big fan for several years now — thank you for writing and maintaining such a great plugin!

    We are seeing a slight nuance when performing a search for a specific author who is commonly known by their first + middle + last name (Sharon Reigie Maynard), where the newest posts from this author DO NOT appear at the top of the list.

    ex: https://www.womensradio.com/?s=sharon+riegie+maynard

    However, when searching for just two terms (first name + last name aka “Sharon Maynard”), the newest posts DO appear at the top of the list.

    ex: https://www.womensradio.com/?s=sharon+maynard

    2 Questions:

    1) Why would newer posts be pushed to later pages (page 3 in this example) when using a search term with three terms as opposed to two?

    2) How can we ensure that visitors searching for this three term string see the newest posts at the top of the search results?

    Any assistance here is greatly appreciated!

    -Brian & WomensRadio

    https://www.ads-software.com/plugins/search-everything/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey Brian (and WomensRadio),

    thanks for reaching out and for the kind words, much appreciated!
    Unfortunately our plugin uses the WordPress’s default search engine which tries to sort the results by relevance. We’ve never really gave this much thought but to be completely honest, we believe that sorting results by date is a great idea and we will discuss on how to implement this in one of our future release.
    For the time being you can insert the following code:

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

    in the functions.php file (after the last line) found in Appearance->Editor->Theme Functions. Please check the screenshot for easier navigation. Hope this helps!

    Please let me know how it goes, take care and have a nice day,
    Petra

    Thread Starter Brian

    (@womensradio)

    excellent — thanks so much Petra! this snippet of code seemed to do exactly what we were hoping to accomplish!

    again, many thanks!

    Glad to hear it works – you are always welcome to leave a comment or a review about us, if you find the time ??

    All the best,
    Petra

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort Default Search Query by Date?’ is closed to new replies.