WordPress search function includes all of its pages and posts by default. However, if you think you need to exclude specific pages from your search result, you can do that very easily. Simply copy and paste the following snippet on your theme’s functions.php file and update the page.
<?php
function exclude_specific_pages($where = '') {
if (is_search()) {
$exclude = array(xx,xx,xx,xx);
for($x=0;$x<count($exclude);$x ){
$where .= " AND ID != ".$exclude[$x]; } }
return $where; }
add_filter('posts_where','exclude_specific_pages');
?>
However, don’t forget to change the “xx” with your page ID. You can add as many pages as you want within the array.
Comment
Leave a Reply