Wordpress - Remove some pages from search

In WP_Query() there is a 'post__not_in' argument where you can exclude specific post ID's.

You would create a new WP_Query inside of your search.php and use the current $query_args, then add on your 'post__not_in'.

If you wanted to make it more dynamic, you could also build in some post meta where you could do a meta query and exclude all that have "exclude" checked. (look up 'register_meta_box_cb' in register_post_type ).

For example,

add_action('pre_get_posts','wpse67626_exclude_posts_from_search');
function wpse67626_exclude_posts_from_search( $query ){

    if( $query->is_main_query() && is_search() ){
         //Exclude posts by ID
         $post_ids = array(7,19,21);
         $query->set('post__not_in', $post_ids);
    }

}

Tags:

Search