well.. It is possible to do in several ways, one of which is the in_category tag, but I think the best thing would be to order that FROM THE ROOT, by applying the right categories and tags to each post, and then query also tags in combination to categories (if you have a LOT of cities) , or if you have not so many, separate the categories in a hierarchy.
But first look at the in_category tag..
<?php
$recent = new WP_Query("cat=X,Y"); while($recent->have_posts()) : $recent->the_post();
if (in_category(X) && in_category(Y)) { ?>
<div class="myclass">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php }; ?>
<?php endwhile; ?>
Now, If you want to add a limit to the number of posts :
<?php
$recent = new WP_Query("cat=X,Y"); while($recent->have_posts()) : $recent->the_post();
static $limitcount = 0;
if ($limitcount == "1") { break; }
else {
if (in_category(X) && in_category(Y)) { ?>
<div class="myclass">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php $limitcount++;
};
}; ?>
<?php endwhile; ?>
you can also use
if ($counter == "2") { break; }
to set another limit.
and
if (in_category(X) && in_category(Y) && in_category(Z)) if you want to cross check more than 2 categories
hello krembo99,
i tryed your solution but doesnt work. I want to show this posts when i’m viewing page in wp, so i’m not in_category and doesnt work.
but thanks anyway for time you spent
i founded faster than i was thinking
query_posts(array(‘category__and’ => array(3,20)));
here
The solution works if you implement it the right way…
The only thing is , that maybe I did not understood what exactly you need.