Support » Developing with WordPress » Making get_posts retrieve only posts in two categories exclusively, not inclusiv

  • How do I make get_posts retrieve posts that are simultaneously in categories 1 and 2? The code below will get the intersection but also those posts in categories 1 and 2 alone.

    <?php $posts = get_posts(‘numberposts=10&category=1,2’);
    foreach($posts as $post) : ?>
    LOOP
    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • the code above does not solve the problem. I would need something like &category=1+2 or &category:1&2

    you want to put the following around the loop

    <?php if ( in_category('2') ) { ?>
    
    loop
    
    <?php } ?>

    then change your initial get_posts to just category 1.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Making get_posts retrieve only posts in two categories exclusively, not inclusiv’ is closed to new replies.