• I am trying to create a search form that will only draw results from one category. However, so far the form is bringing results from the entire site, pages and categories.

    Here is the form I am currently using.

    <form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
    <div>
    <input type=”text” value=”<?php echo wp_specialchars($s, 1); ?>” name=”s” id=”s” />
    <input type=”hidden” name=”cat” value=”1″ />
    <input type=”submit” id=”searchsubmit” value=”Search” />
    </div>
    </form>

    I only want results from category 1.

    Any help would be appreciated.

    Thank you,
    Janet

Viewing 1 replies (of 1 total)
  • You could add a filter to search queries..

    Untested, but something along the lines of..

    function filter_search( $query ) {
       if($query->is_search) $query->set( 'cat' , 'ID' );
       return $query;
    }
    add_filter( 'pre_get_posts' , 'filter_search' );

    Where ID should be a numeric ID for a category..

Viewing 1 replies (of 1 total)

The topic ‘Category Search Form’ is closed to new replies.