In this code snippet we will share how to exclude custom post type from search results in WordPress. If you are manually registering your post types simply add the exclude_from_search argument before registering.

Use the following code to exclude custom post type from search results:

$labels = array(
	// ...
$args = array(
	'labels'  => $labels
	// ...
	'exclude_from_search' => true, 
	// ...

register_post_type( 'my-custom-type', $args );

If a plugin is creating the custom post type, use the init hook with a high priority to update those arguments after the plugin has registered the post type. To do this, add this to functions.php.

// functions.php
add_action( 'init', 'update_my_custom_type', 99 );
 * update_my_custom_type
 * @author  Joe Sexton 
function update_my_custom_type() {
	global $wp_post_types;
	if ( post_type_exists( 'my-custom-type' ) ) {
		// exclude from search results
		$wp_post_types['my-custom-type']->exclude_from_search = true;

Your custom post type will no longer show up in the WordPress search results.

How to Exclude Custom Post Type from Search in WordPress
5 (100%) 3 votes

(Visited 43 times, 1 visits today)

Leave a Comment

Your email address will not be published. Required fields are marked *