Title: WP_query
Last modified: August 30, 2016

---

# WP_query

 *  [luciandavidescu](https://wordpress.org/support/users/luciandavidescu/)
 * (@luciandavidescu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/)
 * Does the plugin also change the results of WP_query loops ran with the ‘s’ parameter?
 * [https://wordpress.org/plugins/better-search/](https://wordpress.org/plugins/better-search/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253839)
 * If you’re using seamless mode, the plugin modifies the search loops by checking
   if the loop is the main query and is a search loop
 * [https://github.com/ajaydsouza/better-search/blob/master/better-search.php#L1421](https://github.com/ajaydsouza/better-search/blob/master/better-search.php#L1421)
 *  Thread Starter [luciandavidescu](https://wordpress.org/support/users/luciandavidescu/)
 * (@luciandavidescu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253979)
 * I am, so I assume the answer is yes. Than how do I make sure that I order query
   results by relevance? Does orderby=none do the job?
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253981)
 * You should ideally only have a single search loop which is on the search results
   page i.e. “/?s=”
 * And, these are automatically ordered by relevance.
 *  Thread Starter [luciandavidescu](https://wordpress.org/support/users/luciandavidescu/)
 * (@luciandavidescu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253982)
 * That I know, but I also have a custom wp_query under posts, that displays a list
   of related posts based on searching (with ‘s’ parameter) for a chosen keyword.
   So the questions are – will the plugin influence the results and if so can i 
   sort them by relevance rather than date?
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253986)
 * I don’t think it should because the custom query would not be classified as the
   main loop by WordPress.
 * That being said, if it does, then the results will automatically be sorted by
   relevance.
 *  Thread Starter [luciandavidescu](https://wordpress.org/support/users/luciandavidescu/)
 * (@luciandavidescu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253987)
 * Well, default WP_Query behaviour is to orderby=date and order=DESC, so i thought
   i’d have to change that in order not to get results resorted chronologically.
   Was hoping orderby=none would do just that, but it seems that it’s not really
   documented anywhere.
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253989)
 * Could you please post the existing query you are using and I could potentially
   assist there.
 * If you’re passing a specific set of posts, you could use orderby => “post__in”
 *  Thread Starter [luciandavidescu](https://wordpress.org/support/users/luciandavidescu/)
 * (@luciandavidescu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253992)
 *     ```
       $slug = str_replace('-','+',$post->post_name);
       $args = array('s' => $slug,'posts_per_page' => '5','orderby' => 'none'); // is the last one ok?
       $search_slug = new WP_Query( $args );
       if ( $search_slug->have_posts() ) {while ( $search_slug->have_posts() ) {$search_slug->the_post();
       include 'snippet.php'; }
       }
       wp_reset_postdata();
       ```
   
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253993)
 * Hi, you could try this:
 *     ```
       $slug = str_replace('-','+',$post->post_name);
       $search_ids = arrary();
       		$matches = get_bsearch_matches( $slug, 0 );		// Fetch the search results for the search term stored in $search_query
       		$searches = $matches[0];		// 0 index contains the search results always
       		if ( $searches ) {
       			$search_ids = wp_list_pluck( $searches, 'ID' );
       		}
       	}
   
       	$args = array(
       		'post__in' => $search_ids,
       		'order_by' => 'post__in',
       		'posts_per_page' => '5',
       	);
   
       $search_slug = new WP_Query( $args );
       if ( $search_slug->have_posts() ) {while ( $search_slug->have_posts() ) {$search_slug->the_post();
       include 'snippet.php'; }
       }
       wp_reset_postdata();
       ```
   

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘WP_query’ is closed to new replies.

 * ![](https://ps.w.org/better-search/assets/icon-256x256.png?rev=2988729)
 * [Better Search - Relevant search results for WordPress](https://wordpress.org/plugins/better-search/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/better-search/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/better-search/)
 * [Active Topics](https://wordpress.org/support/plugin/better-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/better-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/better-search/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 9 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/wp_query-12/#post-6253993)
 * Status: not resolved