Past Events
Displaying past events by custom field date
In this example:
Ajax Load More will order past events by custom field (date) value – upcoming events will be dropped from the listing.
The following example uses Advanced Custom Fields to create an event date custom field (event_date) for an events post type.
Ajax Load More will run a query for the event_date custom field and only display results where the value is less than today’s date.
The following shortcode was used to create the Past Events example.
<?php $date = date("Y-m-d"); ?>
[ajax_load_more post_type="events" meta_key="event_date" meta_value="'.$date.'" meta_compare="lessthan" meta_type="DATE" order="DESC" orderby="meta_value_num" posts_per_page="3" button_label="More Events"]
Variables are being passed into this Ajax Load More shortcode and therefore it must be added to a page using the do_shortcode method.
The following Repeater Template was used to create the Past Events example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<li> <?php global $post; ?> <?php if (has_post_thumbnail()) { the_post_thumbnail(array(150,150)); }?> <h3><a href="#"><?php the_title(); ?></a></h3> <?php $event_date = get_field('event_date', $post->ID))); ?> <p class="entry-meta"> <?php echo $event_date; ?> <?php if(get_field('event_time', $post->ID)) echo ' @' .get_field('event_time', $post->ID); ?> </p> <?php the_excerpt(); ?> </li> |