I need to display all the categories I created for a custom post type then inside of each category I need to loop all the posts that are tied to that category.
I tried constructing my WP_Query a number of different ways and I can't get it to work at all.
Here's the code I have now:
$categories = get_categories('taxonomy=faqcat&order=DESC');
foreach ($categories as $cat) {
// loop through all posts tied to category here
}
Updated Code.. still doesn't work.. keeps displaying the same posts in each category.
<?php
$categories = get_categories('taxonomy=faqcat&order=DESC');
foreach ($categories as $cat) :
echo '<h1>' . $cat->name . ' (' . $cat->cat_ID . ' )</h1>';
$q = new WP_Query(array('cat_ID' => $cat->cat_ID, 'post_type' => 'faq', 'tax_query' => array('taxonomy' => 'faqcat')));
if ($q->have_posts()) : while ($q->have_posts()) : $q->the_post();
echo $post->ID;
?>
<pre> <B><?php the_title(); ?></b></pre>
<p><?php the_content(); ?></p>
<br/>
<?php endwhile;
else:
?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php
endif;
endforeach;
?>