fbpx
How to Exclude a Custom Post Type from WordPress Search

How to Exclude a Custom Post Type from WordPress Search

Here is how to exclude a custom post type from the WordPress search results. This can come in handy if you, for instance, is using a custom post types for things like a slider on the home page that aren’t meant to be a stand-alone post.

Instructions
Add the following code to your WordPress functions.php file.

add_action('init', 'codex_custom_init');
function codex_custom_init()
{

  $args = array(
    'exclude_from_search' => true, // 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);
}

Related links
http://codex.wordpress.org/Function_Reference/register_post_type

WordPress Snippet Info

Tested with Wordpress v. NA

How to Exclude a Custom Post Type from WordPress Search
4.7 (94.29%) 7 vote[s]
Please report broken snippets.
Report Broken Snippet

Recent Comments