Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm just trying to find a way to narrow my current search bar so that it only searches within my 'events' custom post-type.

I do not want the search to index any other post type, only 'events'.

Here's the search bar:

<form id="searchform" action="http://localhost:8888/ltc" method="get">
        <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
        <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
    </form>

And the search.php:

<?php if ( have_posts() ) : ?>
            <h1><?php printf( __( 'Search Results for: %s', 'twentyten' ), '' . get_search_query() . '' ); ?></h1>
            <?php
            /* Run the loop for the search to output the results.
             * If you want to overload this in a child theme then include a file
             * called loop-search.php and that will be used instead.
             */
             get_template_part( 'loop', 'search' );
            ?>

(I haven't actually edited the default search.php page yet, as I just want to get the indexing correct first)

Thanks

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

To search for a custom post type , you can add to the query &post_type=events , to achieve this just edit your form like this

<form id="searchform" action="http://localhost:8888/ltc" method="get">
        <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
        <input type="hidden" name="post_type" value="events" />
        <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
</form>

You can do this for any post type (needs to be an existent one or will be discarded) and will work just fine

share|improve this answer
add comment

To tag along with Hansy check out my post here: search only pages if on page to use radio checkboxes to give the users an option of what they wish to search.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.