If you have a Web or Blog site on WordPress platform, then you should have known by now that the regular WordPress search option includes your pages on your search result.
This could be a great idea to include literally everything on your search result. However, if you are running a Blog site on WordPress platform, you may not want to include pages on your search result. For an example, I didn’t find it relevant to include Pages on my search result, as the page links are at the top of the site layout anyway. It would be lot easier for users to go through the links rather than look for it. I hope you got my point. Now, if that’s what exactly you are looking for, this is the post for you. Go ahead & read the rest of it.
We can exclude any page from our search results simply just by adding the following snippet code on our functions.php file of the theme. However, we need to identify and add the page arrays that we want to exclude on this code. Seems like it’s hard to get? trust me it’s not at all. All we are doing here is just telling the WordPress search not to look for some specific pages. Don’t worry I will tell you how to find page array but before that, take a close look at the code.
function filter_where($where = ”) {
if ( is_search() ) {
$exclude = array(xxx,xxx,xxx);
for($x=0;$x<count($exclude);$x++){
$where .= ” AND ID != “.$exclude[$x]; } }
return $where; }
add_filter(‘posts_where’, ‘filter_where’);
?>
As you go through this snippet code, you will find “xxx” mentioned three times on fourth line of the code & separated by comma (,). These “xxx” stands for the page arrays which are suppose to be on numerical value.
How to Find Page Arrays
Step 1: Once logged in to your WordPress site, go to Pages menu.
Step 2: Take a look at the Pages you have & put your cursor on the top of the Title of your page.
Step 3: While hovering through your Page Titles, look at the status bar. It should show something like “post=1234“.
Step 4: Write down the number for each page you have. These are the arrays for your pages.
Since you found your Page arrays, all you have to do now is to copy and paste these number on our snippet code (mentioned above). Once you are done with that, just update your functions.php file. You are pretty much done. Just go back to your WordPress site and search with any keyword relevant to your pages. It won’t show your pages. Hope that helps. Let us know, if you could make it work or not. Thanks.
You can follow us on Twitter, add on your Google+ circle or Like our Facebook page to get the latest news, updates and reviews.








Comments: