Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The native search page runs a query like so:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.* 
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.

add_filter('pre_get_posts','my_search_filter');
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
add comment

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

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.