searchform template

Limiting WordPress Search to Custom Post Types

I have now written a more extensive article on WordPress search at [WP Theme Tutorial][search].

While working with custom post types I’ve found the need a few times to search only within the custom post type. A great example would be on a list of community resources. On the resources page it would make sense to only search the resources. With the snippet below you can force the search form to search only the custom post type in question. Notice the conditional tags to limit this modification to the resources page only.

[php]
<form method="get" id="searchform" action="/”>

<input type="search" class="text" value="search resources ” name=”s” id=”s” />

[/php]

I’ll admit that this isn’t the ultimate option. I’d like to have the user click a checkbox and be able to limit the searches to a custom post type, or inside the current search.

[search]: http://wpthemetutorial.curtisdev.ca/2011/10/17/enhancing-wordpress-search/ “Enhancing WordPress Search”

%d bloggers like this: