Exclude a custom post type from search

Here is an example of how to exclude a custom post type from search results. Handy if using them for things like a slider on home page that aren’t meant to be a stand alone posts.

Code Snippet:

<?php
add_action('init', 'codex_custom_init');
function codex_custom_init()
{

  $args = array(
    'exclude_from_search' => false, // the important line here!
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','author','thumbnail','excerpt','comments')
  );
  register_post_type('book',$args);
}
?>

Posted in Pages, Posts, Conditional