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.

I want to make a specific page unsearchable. I don't want it's text to show up when i'm searching some text in the search box (on the sidebar on most themes).

share|improve this question
    
I'm guessing i would have to edit The-Loop in some way, but how? –  vsync Dec 19 '12 at 23:59
    
Please always add additional info to the question as edit instead of adding comments. Thanks. –  kaiser Dec 20 '12 at 8:02

1 Answer 1

function hide_from_search($qry) {
  if (is_search()) $qry->query_vars['post__not_in'][] = xXx;
  return $qry;
}
add_filter('pre_get_posts','hide_from_search');

The xXx is the ID number of the page to exclude. Just read it out of the URL on the backend. When you are editing the page you want to exclude look at the URL bar. You should see "post=xXx" in there.

share|improve this answer
    
cool, thanks. I ended up putting this in the beginning of The Loop: if( get_post_type() != 'page' ) : ... because i wanted to search only inside posts anyway and not inside pages –  vsync Dec 23 '12 at 18:29

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.