Display posts matching two categories (wordpress)

I need to select posts that belong in TWO categories.
How do I add “category__and” into this code?
Please help!

[php]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();[/php]

Not a WP expert, but I think you need to specify your query in the cat part of your query.

http://codex.wordpress.org/Function_Reference/query_posts#Exclude_Categories_From_Your_Home_Page

http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

$query = new WP_Query( 'cat=2,6,17,38' );

So in your case does this work?

extract(shortcode_atts(array(
  		'titleonly' => 'n',
  		'cat' => '2,6,13',
  		'num' => 5,
  		'offset' => '',
  	), $atts));

… ty!.. I’m afraid that’s not it at all.
…I tried to figure it out but a huge headache hit me and I felt bad down groaning…

Exclude post from a category would help also :slight_smile:

You would need to remove the other cat assignment of course.

Sponsor our Newsletter | Privacy Policy | Terms of Service