• Resolved kolshix

    (@kolshix)


    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 6 years, 5 months ago by kolshix.
    • This topic was modified 6 years, 5 months ago by kolshix.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kolshix

    (@kolshix)

    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

    (@msaari)

    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

    (@kolshix)

    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 6 years, 5 months ago by kolshix.
    • This reply was modified 6 years, 5 months ago by kolshix.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘pre_get_posts + post__in’ is closed to new replies.