Title: pre_get_posts + post__in
Last modified: June 10, 2018

---

# pre_get_posts + post__in

 *  Resolved [kolshix](https://wordpress.org/support/users/kolshix/)
 * (@kolshix)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/pre_get_posts-post__in/)
 * I use pre_get_posts filter for “exact-match” – everything works perfectly.
 * I want to add one more filter search among id “in-fav” (This is a filter for 
   searching among fovorites posts)
 *     ```
       // url ?s=family&exact-match=1&in-fav=1
       function search_exact_match($query) {	
              	if ($query->is_search && isset( $_GET['in-fav'] )   ) {
       		$query->set( 'post__in', array(63798,17137,101565)  ); // fav ID's 
       	}
       	if ($query->is_search && isset( $_GET['exact-match'] )   ) {
       		$exact_match = '"' . esc_attr( get_search_query( ) ). '"';		
       		$query->query_vars['s'] = $exact_match;	
       	} else {
       		return false;
       	}
       }
       add_action('pre_get_posts', 'search_exact_match');
       ```
   
 * when the plugin relevanssi is enabled – code(filter) does not work
    (search is
   looking for in all id’s site)
 * when the plugin relevanssi is off – **code(filter) filter work**
    (search is 
   looking for in array(63798,17137,101565) id’s site)
 * how to properly perform this filter with relevanssi?
    -  This topic was modified 7 years, 10 months ago by [kolshix](https://wordpress.org/support/users/kolshix/).
    -  This topic was modified 7 years, 10 months ago by [kolshix](https://wordpress.org/support/users/kolshix/).

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

 *  Thread Starter [kolshix](https://wordpress.org/support/users/kolshix/)
 * (@kolshix)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/pre_get_posts-post__in/#post-10384778)
 * resolved
 * The problem was in the plugin “simply-exclude”
    I do not even know how to be 
   The old plugin can not be disabled ;(
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/pre_get_posts-post__in/#post-10385231)
 * You can try moving your filter to run after Simply Exclude. The default priority
   for Simply Exclude is 999; if you run your filter on priority 1000, it should
   run after Simply Exclude and work better.
 *  Thread Starter [kolshix](https://wordpress.org/support/users/kolshix/)
 * (@kolshix)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/pre_get_posts-post__in/#post-10393205)
 * priority 1000 not work.
    I had to enter the code into the plugin simply-exclude(
   can someone help it be)
 *     ```
       ... 
       function se_get_action_data($action='') 
       ...
       	$arr_fav_ids = get_user_meta(  get_current_user_id(), "wpfp_favorites", true);
   
       	$fav_search = $_GET['in_fav'] ;
       	$fav_search = mb_substr( $fav_search , 0, 10);
       	$fav_search = trim($fav_search);
       	$fav_search = stripslashes($fav_search);
       	$fav_search = htmlspecialchars($fav_search);
   
       	if (  $fav_search == 1  ){	
       	   foreach($this->se_cfg['data']['post_types'] as $key => $data){ 
                       // ID search
       		$key = array_search($id, $arr_fav_ids);
       		if ($key !== false){
                           // ORIGINAL CODE
                       }
               }else{	
                    // ORIGINAL CODE
               }
       ...
       ```
   
    -  This reply was modified 7 years, 10 months ago by [kolshix](https://wordpress.org/support/users/kolshix/).
    -  This reply was modified 7 years, 10 months ago by [kolshix](https://wordpress.org/support/users/kolshix/).

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

The topic ‘pre_get_posts + post__in’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=2025044)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

## Tags

 * [post__in](https://wordpress.org/support/topic-tag/post__in/)
 * [pre_get_posts](https://wordpress.org/support/topic-tag/pre_get_posts/)

 * 3 replies
 * 2 participants
 * Last reply from: [kolshix](https://wordpress.org/support/users/kolshix/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/pre_get_posts-post__in/#post-10393205)
 * Status: resolved