WordPress   

Exclude any custom post type from WordPress search

This WordPress code snippet can be to exclude any specific post type from the WordPress search results. In this example, In this example, I’m using events custom post type, you simply replace events with your required custom post type and use this code snippet in your WordPress website.

//Exclude posts from search
add_action( 'init', 'exclude_cpt_from_search', 99 );
function exclude_cpt_from_search() {
    global $wp_post_types;
	$wp_post_types['events']->exclude_from_search = true;
}
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us