posts_where filter is ignored
-
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,3it 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.
The topic ‘posts_where filter is ignored’ is closed to new replies.