How to Display Posts in a Specific Category on your WordPress Search Results Page

Recently, I needed a search form that searched and resulted in posts from a specific category. I solved it by adding a hidden input field to my searchform.php file as follows:

Note, in the code above, I am searching posts in the category whose id is 21.

Pretty nifty, eh?

Thanks to WP Explorer for the idea.

Posted in

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to and

Follow Toby's contributions on Github and


  1. talha on April 12, 2013 at 5:56 am

    I have tried this , but it shows only 1 post of this category
    how can i resolve this ?

    • toby on April 16, 2013 at 9:10 pm

      I am guessing that you have a query running on search.php that displays only 1 post or that your “Settings”->”Reading” are set to display 1 post.