Title: category__and example
Last modified: August 19, 2016

---

# category__and example

 *  Resolved [rrim_ryan](https://wordpress.org/support/users/rrim_ryan/)
 * (@rrim_ryan)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/category_and-example/)
 * I am having trouble using the category__and parameter within query_posts() and
   am looking for some help with my code. The template I’m editing is category.php(
   based on archive.php). Here is what I have so far.
 *     ```
       <?php
   
       	get_header();
   
       	query_posts(array('showposts' => 1, 'category__and' => array(2,6)));
   
       	if (have_posts()) : ?>
   
       		  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       		  <?php /* If this is a category archive */ if (is_category()) { ?>
       		<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
       		  <?php } ?>
       		<?php while (have_posts()) : the_post(); ?>
       			<div <?php post_class() ?>>
       				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>""><?php the_title(); ?></a></h3>
       				<?php the_content() ?>
       			</div>
       		<?php endwhile; ?>
       	<?php else :
       		printf("<h2 class='center'>Sorry, but there aren't any posts in the %s category yet.</h2>", single_cat_title('',false));
       		get_search_form();
       	endif;
   
       	get_sidebar();
       	get_footer(); 
   
       ?>
       ```
   
 * Instead of seeing the one post that is part of both category 2 and 6, I see “
   Sorry, but there aren’t any posts in the category yet.”

Viewing 1 replies (of 1 total)

 *  Thread Starter [rrim_ryan](https://wordpress.org/support/users/rrim_ryan/)
 * (@rrim_ryan)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/category_and-example/#post-1030147)
 * Nevermind… my post wasn’t in category 6 and it was working as written.

Viewing 1 replies (of 1 total)

The topic ‘category__and example’ is closed to new replies.

## Tags

 * [category__and](https://wordpress.org/support/topic-tag/category__and/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [rrim_ryan](https://wordpress.org/support/users/rrim_ryan/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/category_and-example/#post-1030147)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
