Search form help,please

Discussion in 'PHP' started by mccomf, Jun 11, 2011.

  1. #1
    Hey all,
    I have a problem with the custom search form in wordpress.
    I can only search one category at a time. I would like to combine the categories so I can have i final result . Example: if i choose CATEGORY1 and then CATEGORY2 and CATEGORY3 and CATEGORY4 it will give me the result of all the categories with that criteria.

    Here is the code:

    <?php $listings1 = get_option('listings1');
    $listings2 = get_option('listings2');
    $listings3 = get_option('listings3');
    $listings4 = get_option('listings4'); ?>
    <div id="listings">
    	<div id="listings-content">
    		<h4 class="title"><span><?php _e('Browse Listings','n'); ?></span></h4>
    		
    		<div id="listings-options">
    		
    			<form method="get" action="<?php bloginfo('url'); ?>" class="clearfix">
    				<div class="select">
    					<select class="option-listing" name="option-listing">
    						<?php foreach ($listings1 as $item) { ?>
    							<option value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?></option>
    						<?php } ?>
    					</select>
    				</div> <!-- end .select -->
    				
    				<input class="view-button" type="submit" value="view" name="submit" />
    			</form>
    			
    			<form method="get" action="<?php bloginfo('url'); ?>" class="clearfix">
    				<div class="select">
    					<select class="option-listing" name="option-listing">
    						<?php foreach ($listings2 as $item) { ?>
    							<option value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?></option>
    						<?php } ?>
    					</select>
    				</div> <!-- end .select -->
    				
    				<input class="view-button" type="submit" value="view" name="submit" />
    			</form>
    			
    			<form method="get" action="<?php bloginfo('url'); ?>" class="clearfix">
    				<div class="select">
    					<select class="option-listing" name="option-listing">
    						<?php foreach ($listings3 as $item) { ?>
    							<option value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?></option>
    						<?php } ?>
    					</select>
    				</div> <!-- end .select -->
    				
    				<input class="view-button" type="submit" value="view" name="submit" />
    			</form>
    			
    			<form method="get" action="<?php bloginfo('url'); ?>" class="clearfix">
    				<div class="select">
    					<select class="option-listing" name="option-listing">
    						<?php foreach ($listings4 as $item) { ?>
    							<option value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?></option>
    						<?php } ?>
    					</select>
    				</div> <!-- end .select -->
    				
    				<input class="view-button" type="submit" value="view" name="submit" />
    			</form>
    		
    		</div> <!-- end #listings-options -->
    	</div> <!-- end #listings-content -->
    	
    	<div id="listings-bottom">
    		<div id="search-container">
    			<form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
    				<input type="text" id="searchinput" name="s" value="<?php _e('or search our property listings...','n'); ?>"/>
    			</form>
    		</div> <!-- end #search-container -->
    	</div> <!-- end #listings-bottom -->
    </div> <!-- end #listings -->
    PHP:


    image is here:


    [​IMG]



    You can see the four buttons there but I will replace it with the one.


    Thank you in advance.
     
    Last edited: Jun 11, 2011
    mccomf, Jun 11, 2011 IP
  2. mccomf

    mccomf Active Member

    Messages:
    517
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Anyone who could sort this out for me.I will a few $.
     
    mccomf, Jun 11, 2011 IP
  3. niks00789

    niks00789 Well-Known Member

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Firstly i dunno how wordpress works... but i guess what you are trying to do can be achieved by using checkboxes and not drop down menus!

    it would go something like this (i'm not sure if it will work, but you can give it a try):

    
    <?php 
    $listings1 = get_option('listings1');
    $listings2 = get_option('listings2');
    $listings3 = get_option('listings3');
    $listings4 = get_option('listings4'); ?>
    <div id="listings">
        <div id="listings-content">
            <h4 class="title"><span><?php _e('Browse Listings','n'); ?></span></h4>
            
            <div id="listings-options">
            
                <form method="get" action="<?php bloginfo('url'); ?>" class="clearfix">
                    <div class="select">
                            <?php foreach ($listings1 as $item) { ?>
                                <input type="checkbox" name="option-listing" value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?><br/>
                            <?php } ?>
                            <?php foreach ($listings2 as $item) { ?>
                                <input type="checkbox" name="option-listing" value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?><br/>
                            <?php } ?>
                            <?php foreach ($listings3 as $item) { ?>
                                <input type="checkbox" name="option-listing" value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?><br/>
                            <?php } ?>
                            <?php foreach ($listings4 as $item) { ?>
                                <input type="checkbox" name="option-listing" value="<?php echo $item; ?>"><?php echo get_cat_name($item); ?><br/>
                            <?php } ?>
                    </div> <!-- end .select -->
                    
                    <input class="view-button" type="submit" value="view" name="submit" />
                </form>
            
            </div> <!-- end #listings-options -->
        </div> <!-- end #listings-content -->
        
        <div id="listings-bottom">
            <div id="search-container">
                <form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
                    <input type="text" id="searchinput" name="s" value="<?php _e('or search our property listings...','n'); ?>"/>
                </form>
            </div> <!-- end #search-container -->
        </div> <!-- end #listings-bottom -->
    </div> <!-- end #listings -->
    
    PHP:
     
    niks00789, Jun 12, 2011 IP
  4. mccomf

    mccomf Active Member

    Messages:
    517
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Thanks niks00789 but it shows result from every category selected.What Im looking for is that search results would be filtered based on the categories selected.
     
    mccomf, Jun 12, 2011 IP