WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query posts belonging to 2 categories (3 posts)

  1. peterbra
    Member
    Posted 3 years ago #

    Hi,
    I have categories:
    Circuit1, Circuit2. Circuit3, Circuit4
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

    Now I assign each post to both Circuit and Day category.

    My question is how to query a posts that are assigned ONLY TO BOTH of the categories ?

    E.g. I want to display posts that are assigned ONLY to Monday and Circuit1 category (ignoring all other posts) ?

    I've tried this code but this returns the "EMPTY" posts as in category circuit1 I have posts that are not assigned to Monday category as well, but the WP "sees" that they exist in circuit1 category and I'm getting just empty div for those posts (but I'm sure there is more elegant way for doing this :

    <?php query_posts('category_name=Monday&posts_per_page=100');
             while (have_posts()) : the_post();
    			$post = get_post($id);
    			if ( in_category('circuit1') ) {
    				echo get_the_post_thumbnail($id);
    				the_excerpt();
    			}
    	?>
      <?php endwhile; ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

  3. peterbra
    Member
    Posted 3 years ago #

    Now that was so obvious, I've just read that (20 minutes ago) and I didn't see that example o.O Must be that it's bed time :)
    THANKS SO MUCH !!

Topic Closed

This topic has been closed to new replies.

About this Topic