I would like to set up a widget to filter my post by categories. Let's say, I do have two different categories, "Countries" and "length of stay" with sub categories. Here is an example of what I have:
Countries
- China
- Laos
- Vietnam
Length of stay
- 2-4 Days
- 5-7 Days
- 8-10 Days
What I want, is to filter posts by multiple categories. So, If the user is checking the country "Laos" and a length of stay of "2-4Days", I would like to retrieve only posts where the category "Laos" AND the category "2-4Days" has been attached.
I tried to use the Query Multiple Taxonomies pluging. However, this plugging is retrieving all posts with the "Laos" category and all posts with the length of stay of "2-4Days".
I know, that I can filter post with this query, but, I need some help to create this widget with the submit button. Also, I would like to customise it to remove parent categories and display them as a title (remove the checkbox of "Countries" and "Length of stay" and add to them a specific class)?
Working query:
<?php
// cat 42=Laos cat 57=2-4Days
$my_query_1 = new WP_Query(
array(
'category__and' => array(42,57)
)
);
while ($my_query_1->have_posts()) {
$my_query_1->the_post();
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?><?php the_excerpt(); ?>
</a>
<?php
}
Thanks for helping
while(){}
instead of<?php while (): ?> <?php something(); ?><?php endwhile; ?>
? The mix of altsyntax and an opening closing php tags here there and everywhere makes it very difficult to see what's going on. AlsoWP_Query
notWP_query