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”

To get a head start, join thousands of other men and Stop The Struggle.

Get my free eBook to help you stop working all the hours without traction.

You’ll also get a weekly email with good resources to help you do family with the same intention you do your work. Both need to run well if you want to win.

%d bloggers like this: