Loop Categories Showing Posts in Cat ONLY for Custom Post Type?
-
I’m having a devil of a time with this. I hope someone can help.
I have several custom post types in use around a single category system. In other words, CustomA, CustomB, and CustomC all use the same categories for identification. They’re easy to query except in the below, which shows every category, even if it doesn’t have any posts in the identified post_type. Can you help me exclude those categories that don’t include posts in the specified post_type?
<?php // get all the categories from the database $cats = get_categories(); // loop through the categries foreach ($cats as $cat) { // setup the cateogory ID $cat_id= $cat->term_id; // Make a header for the cateogry echo "<h3>".$cat->name."</h3>"; // create a custom wordpress query query_posts("cat=$cat_id&post_type=resource&post_per_page=-1"); //-1 shows all posts per category. // start the wordpress loop! if (have_posts()) : while (have_posts()) : the_post(); ?> <?php // create our link now that the post is setup ?> <a href="<?php the_permalink();?>"><?php the_title(); ?></a> <?php echo '<hr/>'; ?> <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?> <?php } // done the foreach statement ?>
Thank you in advance.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Loop Categories Showing Posts in Cat ONLY for Custom Post Type?’ is closed to new replies.