Prevent A Specific Custom Post Type Showing In WP Search Results Page

Question

I’ve excluded certain pages from the WP Search with the code below in my functions.php file.

I also need to exclude a custom post type called ‘sites’.

I can’t seem to find the custom post type equivalent of the post__not_in argument ?

I don’t want to remove it in the custom post type code itself under public => false because I still want it to have its own url etc.

Does anyone know how to remove a specific custom post type from showing up in WP Search?

Any help would be wonderful !

// EXCLUDE CERTAIN PAGES FROM SEARCH RESULTS (PAGE IDs IN ARRAY)

function tp_remove_pages( $query ) {
  if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
    $query->set( 'post__not_in', array( 11,84,118,115,123,132 ) );
  }
}
add_action( 'pre_get_posts', 'tp_remove_pages' );
0
, , , The Chewy 3 years 2020-05-30T22:11:27-05:00 0 Answers 90 views 0

Leave an answer

Browse
Browse