I have a custom post type on a band site for displaying lyrics. This custom post type has custom fields like for example band. Naturally I'm able to retrieve all lyrics listed, but now I want to make a sorting functions. I want to have a drop down with the band names that has lyrics.
Therefore I want to get all band names from custom post-type lyrics, and group them (like in a MySQL group).
My code so far (this display all bands ungrouped):
<?php $bandQuery = new WP_Query(array('post_type' => 'lyrics', 'meta_key' => 'band', 'orderby' => 'meta_value', 'order' => 'ASC', 'posts_per_page' => '-1')); ?>
<?php if(have_posts()) { while ( $bandQuery->have_posts() ) { $bandQuery->the_post(); ?>
<?php $band = get_post_meta($post->ID, 'band', true); ?>
<div><?php echo get_the_title($band); ?></div>
<?php }} // End the loop. ?>