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.


  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.