KB Article 307

Exclude Pages from Search Results Page on WordPress sites

Article last updated on: October 16, 2019 by Justin Parks
Filed under: arcticspasbrandcore.com arcticspascore.com Support Team Wordpress Development


On arcticspasbrandcore.com and arcticspascore.com we will need to HIDE pages on the search results pages so they cannot be discovered by visitors.

In order to do this we have included a hook in the functions.php file of each site:

function exclude_page_search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set( ‘post__not_in’, array( 1234, 1235, 1236 ) );
}
return $query;
}
}

Where 1234, 1235, 1236 are the page ids of the pages to be excluded from the search results.

All pages excluded are recorded here:

https://docs.google.com/spreadsheets/d/1xdSCi1uAPITUlvr4nGnwztmBIIUqOijNFW4MZtHHw2E/edit#gid=0