WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The native search page runs a query like so:

FROM wp_posts 
WHERE 1=1 AND (((wp_posts.post_title LIKE '%keyword%') 
OR (wp_posts.post_content LIKE '%keyword%')) 
AND (wp_posts.post_password = '') 
AND wp_posts.post_type IN ('post', 'page', 'attachment') 
AND (wp_posts.post_status = 'publish') 
ORDER BY wp_posts.post_date DESC LIMIT 0, 10

I am passing specific post IDs to the query by hooking into pre_get_posts so I don't need the other WHERE conditions related to the keyword. e.g.

function my_search_filter($query) {
    if ($query->is_search) {
            // post IDs within distance X
        $matches = array(1,3,5);
        $query->query_vars['post__in'] = $matches;


How can I remove the conditions related to post_title and post_content from the query object by modifying the existing query rather than writing a new one.

share|improve this question
Why are you using a search if you don't want to actually search anything...? Could you give a brief outline of what you are trying to achieve - there is probably a better than modifying a search query :D – Stephen Harris Feb 24 '12 at 10:28
I'm geocoding the address the user enters in the search form to build a list of matching post IDs within a certain distance which I store in $matches. – kidrobot Feb 24 '12 at 22:00
up vote 1 down vote accepted

Filter posts_where or posts_search. See this answer for a couple of examples.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.