Skip to content

Instantly share code, notes, and snippets.

@tessak22
Created December 10, 2017 18:01
Show Gist options
  • Save tessak22/77d6e727ff410fb593b6bfa34e1ff920 to your computer and use it in GitHub Desktop.
Save tessak22/77d6e727ff410fb593b6bfa34e1ff920 to your computer and use it in GitHub Desktop.
Templating for Custom Post Type sorting by ACF Date Field
<?php
$today = current_time('Ymd');
$args = array(
'post_type' => 'events',
'posts_per_page' => '20',
'meta_key' => 'speaking_date',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
'key' => 'speaking_date',
'compare' => '>=',
'value' => $today,
),
),
);
$children = new WP_Query($args);
?>
<?php if ($children->have_posts()) : ?>
<?php while ($children->have_posts()) : $children->the_post(); $fields = (object) get_fields(); ?>
<div class="event row">
<div class="event-logo col-sm-4">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'large', array( 'class' => 'img-responsive' ) ); ?></a>
</div>
<div class="event-details col-sm-8">
<h3 class="underline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<h5><?php echo $fields->speaking_title; ?></h5>
<p class="call-to-action"><a href="<?php the_permalink(); ?>">Read More</a></p>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment