Skip to content

Instantly share code, notes, and snippets.

@jonkpirateboy
Last active August 29, 2015 14:21
Show Gist options
  • Save jonkpirateboy/6fdba227e10e7fea39ac to your computer and use it in GitHub Desktop.
Save jonkpirateboy/6fdba227e10e7fea39ac to your computer and use it in GitHub Desktop.
Sort by taxonomy
$timestamps = get_terms( 'timestamp', array(
'hide_empty' => true,
'orderby' => 'name',
) );
if ( ! empty( $timestamps ) && ! is_wp_error( $timestamps ) ){
echo '<ul>';
foreach ( $timestamps as $timestamp ) {
echo '<li>' . $timestamp->name . '</li>';
$args = array('post_type' => 'event',
'tax_query' => array(
array(
'taxonomy' => 'timestamp',
'field' => 'name',
'terms' => $timestamp->name,
),
),
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata();
}
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment