Title: Display posts matching two categories.
Last modified: August 22, 2016

---

# Display posts matching two categories.

 *  [sob1](https://wordpress.org/support/users/sob1/)
 * (@sob1)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/display-posts-matching-two-categories/)
 * I need to select posts that belong in TWO categories.
    How do I add “category__and”
   into this code? Please help!
 *     ```
       function excerptlist_func($atts) {
       	extract(shortcode_atts(array(
       		'titleonly' => 'n',
       		'cat' => '',
       		'num' => 5,
       		'offset' => '',
       	), $atts));
   
       	$args = array('posts_per_page' => $num, 'offset' => $offset );
       	$id = get_cat_id($cat);
       	$args['cat'] = $id;
   
       	$loop = new WP_Query( $args );
               $posts = array();
               foreach($loop->posts as $p) { $posts[] = $p; }
       	global $post;
       	$opost = $post;
       	ob_start();
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [sob1](https://wordpress.org/support/users/sob1/)
 * (@sob1)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/display-posts-matching-two-categories/#post-5289870)
 * I tried to figure it out myself but a huge headache hit me and I felt bad down
   groaning….
    Exclude post from a category would help also 🙂 Please help!

Viewing 1 replies (of 1 total)

The topic ‘Display posts matching two categories.’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [matching](https://wordpress.org/support/topic-tag/matching/)
 * [two](https://wordpress.org/support/topic-tag/two/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [sob1](https://wordpress.org/support/users/sob1/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/display-posts-matching-two-categories/#post-5289870)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
