WordPress exclude custom post types from search

The following code works in preventing our "Projects" from appearing in the site search results, but it is causing unintended consequences for various filtering on the admin backend. Is there any way to contain the function to only the front end search? function ss_search_filter( $query ) { if ( $query->is_admin() ) : return $query; endif; if ( $query->is_search() && $query->is_main_query() ) { // set the post type to only post types you want returned. $query->set( 'post_type', ['page', 'post', 'product'] ); } return $query; } add_action( 'pre_get_posts', 'ss_search_filter' );

Comment (0)

You’ll be in good company