The template tag, query_posts(), detail the various arguments. Show all posts in category 2 AND 6:
<?php
$args=array(
'category__and' => array(2,6)
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Thanks for the answer, but it’s not the code i want.
I’d like to show only the 6 posts in the cat id 2 and 6, and to be equal posts: 3in id:2 and 3in id:6.
in the code below it show the 6 (img) posts randomly, but not equals with cats id 2&6!!! how can i do it, with only one loop.
<ul>
<?php query_posts('cat=2,6&orderby=rand&showposts=6'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php //call the custom field "image1" //
$var_img01 = get_post_meta($post->ID, "image1", TRUE);?>
<li>
<?php // Insert the custom field "image1" //
if ( $var_img01 ) { ?>
<a href="<?php the_permalink() ?>">
<img src="<?php echo $var_img01; ?>"/>
</a>
<?php } else { ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/no-image.jpg"/>
<?php } ?>
</li>
<?php endwhile; else: ?>
Oops, there is no pruduct in this page!!!
<?php endif; ?>
</ul>
Thanks