Support » Fixing WordPress » Query posts belonging to 2 categories

  • Resolved peterbra

    (@peterbra)


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

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query posts belonging to 2 categories’ is closed to new replies.