Exclude certain pages from WordPress search results

PHOTO EMBED

Wed May 26 2021 10:14:35 GMT+0000 (UTC)

Saved by @Alz #php #wordpress

// Exclude certain pages from WordPress search results
//======================================
function jp_search_filter( $query ) {
  if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
    $query->set( 'post__not_in', array( 827,851 ) );
  }
}
add_action( 'pre_get_posts', 'jp_search_filter' );
content_copyCOPY

https://www.johnparris.com/exclude-certain-pages-from-wordpress-search-results/