• Hi, it’s me again … πŸ˜‰ Didn’t get no reply before, so…
    Here’s the situation:
    I have, let’s say, 5 categories:“Stores”, “Museums”, “Garages”, “Sports”, “Towns”, and the last one – “Towns” is hidden (excluded) from cateogries menus.
    I would like to, when I click on “Stores”, and I get archive page with posts in that category, on the top of that page is form with checkboxes to select child categories of “Towns”.
    So, I would like that I, while on “Stores” archive page,can check one or few boxes with towns, and when clicks “Submit” to display posts that are in – “Stores” AND “New York” AND “Washington” (in other words – stores located in N.Y and Washington).
    Here my code, so far (which doesn’t work, off course):

    <?php $cat_ID = $cat; ?>
    <form action="<?php query_posts(array('category__and' => array($cat_ID,array($categories->term_id)))); ?>">
    <?php $categories=get_categories('child_of=5&hide_empty=0');
    	foreach($categories as $category) {
    		echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";
    		echo $category->cat_name;
    		echo '<br />';    }
    	?>
    	<INPUT TYPE=SUBMIT VALUE="submit">
    </form>
    
    <?php while (have_posts()) : the_post(); ?> ... etc (the loop here ..)

    Any help is really much appretiated …

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Micemade

    (@anydog)

    Ok, I have update, so ignore upper code. Just read the “story” πŸ˜‰
    This code bellow is, I believe on the right track, it just has one flaw – it doesn’t work :D.
    Something is wrong with the category__and part, because when my if loop runs query_posts without category__and it’s ok. When I select checkbox option, the page goes completely blank … πŸ™ (?)
    Here’s code:

    <?php $current_cat_ID = $cat; ?>
    
    <form method="post" action="" id="mjesta">
    
    	<?php
    	$categories=get_categories('child_of=104&hide_empty=0');
    	foreach($categories as $category) {
    		echo '<div class="mjesto">';
    		echo "<input type='checkbox' name='place_id[]' value='$category->term_id' />";
    		echo '<span>'.$category->cat_name.'</span>';
    		echo '</div>';
    	}//end foreach
    
    	$place_id=$_POST['place_id'];
    	while (list ($key,$val) = @each ($place_id)) {
    		$v = "$val,";
    		echo $v;
    	}//end while
    	?>
    	<br />
    	<input type="submit" value="<?php echo(__('show','rab')); ?>" id="botun">
    </form>
    
    </div>
    
    <?php
    if(empty($v)) {
    	query_posts('cat='.$current_cat_ID.'&showposts=5&orderby=title&order=ASC');
    }else{
    	query_posts(array('category__and'=>array($current_cat_ID,$v),'posts_per_page'=>2,'orderby'=>title,'order'=>DESC));
    }//end if
     ?>
    
    <?php while (have_posts()) : the_post(); ?> ... and so on ...

    Pleeeease, help !

    Hi, looking for the same result. did you find any solution by chance?

    Hi, count me in that i’m looking for the same result.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Select multiple categories with checkboxes’ is closed to new replies.