Support » Themes and Templates » Search in either custom post type or category

  • I’m trying to make a searchform which allows the user to search for terms that are either in one of my custom post type pages, or in a post of a certain category.

    For example, say I have custom post type “Products”, under which I have added several pages. Now imagine I have also added some blog entries (Posts), and given them the category “Press releases” (which has ID = 4).

    How can I construct a search query which will look for the search term in both “Products” post-type and category 4, such that it will return any positive results it finds in either?

    Ultimately I’d like to give the user a searchform containing a dropdown with the following options:

    <form action="<?php bloginfo('siteurl'); ?>" id="searchform" method="get">
            <label for="s" class="screen-reader-text">Search for:</label>
            <input type="search" id="s" name="s" value="<?php the_search_query() ?>" />
            <select name="foo1">
    			<option value="">Everything</option>
    			<option value="foo2">Only Products</option>
    			<option value="foo3">Only Press releases</option>
            <input type="submit" value="Search" id="searchsubmit" />

    I am wondering if there is a way to write foo1, foo2, and foo3 so that it does what I would like?

  • The topic ‘Search in either custom post type or category’ is closed to new replies.