• Hello Folks,
    i have a short question, as i am new to filter, this might be easy for you , but it is
    very strange to me, so many somebody has some input for me ?

    I want to exclude some posts from the WP search, and let us say i really need to manipulate the sql query for that.

    i tried a lot to change the “$GLOBALS[‘wp_query’]->request” witch seams to contain
    the search query with no success, until i found the posts_where filter.

    my code:

    function se_postStrip ($where) {
    	global $wpdb;
    	if ( is_search() && isset($_GET['s'])) {
    		$where .= "AND ".$wpdb->posts.".ID is not in (1,2,3)  ";
    		echo $where;
    	}
    	return $where;
    }
    
    add_filter ('posts_where', 'se_postStrip');

    seams to work , as the echo delivers a perfect sql statement.
    BUT the posts with the ID 1,2 and 3 are still in the search result.

    I put the code in the functions.php and in the index.php of my theme, but it
    still results me the posts 1,2,3

    it feals like, i change the query to late … but i have other filters in the same file – and they work… so what am i doing wrong ?

    What can i do that the filter executes me the additional where statement ?

    Best regards and thanks a lot !

    p.s.
    To keep it easy i changed the where statement to “is not in” and i know that there are other ways to exclude IDs , but as i said this is just an example to keep it easy.

    My real where statement its a more complicated, but if i get the “is not in” to run, then i can go on myself.

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter derschwede

    (@derschwede)

    Hey Daniel,

    wow thats quite some time gone 😀
    Jepp i finaly made it – honestly i do not know for sure what projekt it was …
    What i remember that it had nothing to do with the syntax – all of the above worked.

    It was more a “wrong” placement of the hook.

    If i remember correct i tried to place the code in different files, starting with index.php
    and worked my way down the includes – and it worked then.

    It was one of this ” why didnt i try the easiest thing at the beginning” moments.

    Maybe this will help you . I can recheck if i find the code i worked on and then i will come back to you here.

    BR

    My code was overloaded by a plugin called Relevanssi… after hours of trying to understand why… 🙁 ….

    the code was right all the time….

    Thanks for you reply.

    Cheers,

Viewing 2 replies - 16 through 17 (of 17 total)

The topic ‘posts_where filter is ignored’ is closed to new replies.