Event Listing
Order and list events by custom field date
In this example:
Ajax Load More will display upcoming events by custom field (date) value – expired or past events will be dropped from the listing.
The following example uses Advanced Custom Fields to create an event date custom field (event_date) for a custom events post type.
Ajax Load More will query for the event_date and display results where the value is greater than or equal today’s date – check out the Past Events example.
The following shortcode was used to create the Event Listing example.
<?php $date = date("Y-m-d"); ?>
[ajax_load_more post_type="events" meta_key="event_date" meta_value="'.$date.'" meta_compare=">=" meta_type="DATE" order="ASC" orderby="meta_value_num" posts_per_page="2" button_label="More Events" no_results_text="<p>There are no upcoming events. Please check our <a href=\'past-events\'>Past Events</a> for details on previous events.</p>"]
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 Event Listing 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> |