I make a lot of sites that have blogs and I enjoy all of the abilities that WordPress has for finding specific posts. The search option is one of my favorites. However, by default, the search option searches all pages and posts. That isn’t a very good UX (User Experience) when they are specifically in the blog area already. I saw many things that had me going into functions or using plugins and I am not in favor of using those unless I have to.

So the solution was quite simple. I found it in a wordpress.org forum. Simply add the following code in your loop. This was in my search.php file. If you don’t have a search.php file, you can use this in the index.php file. I highly recommend using the search.php file though. You can create the search.php file by copying the content of your index.php file and creating a new file called search.php.

here is the code:

<?php if (is_search() && ($post->post_type==’page’)) continue; ?>

See the image to find where I put the code for my search.php file. This is what worked for me.