WordPress.org

Ready to get started?Download WordPress

Forums

Making get_posts retrieve only posts in two categories exclusively, not inclusiv (3 posts)

  1. yokima
    Member
    Posted 7 years ago #

    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; ?>

  2. yokima
    Member
    Posted 7 years ago #

    the code above does not solve the problem. I would need something like &category=1+2 or &category:1&2

  3. MarkMichon
    Member
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic