Skip to content

Instantly share code, notes, and snippets.

@halfempty
Last active August 29, 2015 14:03
Show Gist options
  • Save halfempty/ef6e539f0c1fb4de0c57 to your computer and use it in GitHub Desktop.
Save halfempty/ef6e539f0c1fb4de0c57 to your computer and use it in GitHub Desktop.
MCA Current Exhibitions example
<?php
global $post;
$args = array(
'post_type' => 'mca_exhibitions',
'posts_per_page' => -1
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) :
setup_postdata( $post );
if ( is_current_exhibition($post->ID) ) :
$fields = get_post_meta( $post->ID, '_mca_exhibition', true );
$startDate = $fields['startyear'] . '-' . $fields['startmonth'] . '-' . $fields['startday'];
$myExhibits[] = Array( 'startDate' => $startDate, 'post' => $post);
endif;
endforeach;
if ( count($myExhibits) > 0 ) :
// Sort the records by startDate, using the custom date_compare() function
usort($myExhibits, 'date_compare');
foreach ( $myExhibits as $exhibit ) :
$post = $exhibit['post'];
setup_postdata( $post );
// A template part containing the markup of the exhibition listing
get_template_part('exhibition-thumbsquare');
endforeach;
else :
echo "<p>No Exhibitions</p>";
endif;
wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment