How to filter WordPress search by custom post type

Add the input hidden field

If you want to limit the WordPress search to a specific custom post type, add a hidden input field with that post type:


This is a form with a search input field and a hidden field which will filter the results only for my "books" custom post type:

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.