• This is part of my current search code:

    <?php
    
        function wp_search_form($form) {
        $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
        '.wp_dropdown_categories('exclude=1 Categories&hide_empty=0&echo=0&selected='.intval($_GET['cat']).'').'
        <input type="text" class="search_input" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
        <input type="submit" alt="Search" class="greybutton float_right" value="Search" />
    
        </div>
        </form>';
        return $form;
    }

    I want to get rid of the dropdown and instead just search the category the user is in at the moment. If the user is a the frontpage they will get to search all categories. If the user is in say the category with the id “3” they will only get results from that category. How do I go about that?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thomasfals

    (@thomasfals)

    I found the answer else where:

    function wp_search_form($form) {
    global $wp_query;
    
    $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
    <input type="hidden" name="cat" value="'. $wp_query->get_queried_object_id() .'" />
    <input type="text" class="search_input" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
    <input type="submit" alt="Search" class="greybutton float_right" value="Search" />
    
    </div>
    </form>';
    return $form;
    }

    I was trying to change your code with the current search code but doesn’t work

    Here’s the current search form

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    
    		<div id="search">
    
    			<input type="text" value="" onclick="this.value='';" name="s" id="s" />
    			<input name="" type="image" src="<?php bloginfo('stylesheet_directory'); ?>/styles/<?php echo "$style_path"; ?>/btn-search.gif" value="Go" class="btn"  />
    
    		</div><!--/search -->
    
    	</form>

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Search current category’ is closed to new replies.