WordPress.org

Ready to get started?Download WordPress

Forums

Search in either custom post type or category (1 post)

  1. David Hunt
    Member
    Posted 2 years ago #

    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">
        <div>
            <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>
    		</select>
            <input type="submit" value="Search" id="searchsubmit" />
        </div>
    </form>

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

Topic Closed

This topic has been closed to new replies.

About this Topic