OK, here's my setup:
Custom post type called "issues" (for a magazine) Posts with custom meta field matching the post ID of the corresponding issue.
When I'm on a single "issue" post page, I want to query all the related posts, and display them grouped by their associated category. I have the post query working, I just can't seem to get my head around the category grouping.
here's my query
<?php
global $post;
// List posts by the terms for a custom taxonomy of any post type
$current = get_the_ID($post->ID);
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'meta_key' => '_rkv_issue_select',
'meta_value' => $current
);
$issue_cats = new WP_Query($args);
if( $issue_cats->have_posts() ) :
?>
<ul>
<?php while ( $issue_cats->have_posts() ) : $issue_cats->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; // end of loop ?>
<?php else : ?>
<?php endif; // if have_posts() ?>
</ul>
<?php wp_reset_query(); ?>