WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Hoping someone can assist but as part of normal WordPress theme searching, how can I add a filter as part of the search to not include certain posts/pages as part of my LOOP?

For example, I want the "Search" to ignore post=234 as part of the loop or posts 123,234,555?

Thanks.

share|improve this question

you can use pre_get_posts filter hook and set the post__not_in parameter of the query ex:

function exclude_from_search_filter($query) {
        if ( !$query->is_admin && $query->is_search) {
                $query->set('post__not_in', array(40, 9) ); // id of page or post
        }
        return $query;
}
add_filter( 'pre_get_posts', 'exclude_from_search_filter' );
share|improve this answer

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.