The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. peterbra
    Posted 5 years ago #

    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);
      <?php endwhile; ?>
  2. Michael
    Forum Moderator
    Posted 5 years ago #

  3. peterbra
    Posted 5 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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic