I have a custom post type called eventitem which I use to create a list of events.
Each eventitem has a title, content and a custom field called date_of_event, which is a string of the format 'yyyymmdd' e.g.: 20120924
I have an events list which pulls all these out and uses the Wordpress 'loop' to iterate over them in date_of_event order (rather than the post date). This works fine
However, on the site's homepage I also need to show the next upcoming event title and date, i.e.: the next 1 post where date_of_event >= today's date, but can't for the life of me work out how to dip into a loop and check the record's custom field against today's date :o
I have this code as a starting point, based on the code that works in my 'event list' page (described above) but obviously that's not pulling back the next event using date_of_event, it's pulling back the most recent post based on post date...
<!-- start latest event -->
<?php $my_query = new WP_Query('post_type=eventitem&posts_per_page=1&orderby=meta_value&meta_key=date_of_event&order=DESC'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $do_not_duplicate = $post->ID; ?>
<?php $datearray = date_parse(get_post_meta($post->ID, "date_of_event", true)); ?>
<?php echo date('l jS M Y', strtotime($datearray['day'] ."-". $datearray['month'] ."-". $datearray['year'])); ?><br/>
<strong><?php the_title(); ?></strong>
<?php endwhile; ?>
<!-- end latest event -->
Any ideas what that query should be so it only returns the next event, using the date_of_event custom field?
(Hope all that makes sense. Thanks in advance!)
If it helps, the custom post types where created using the "WCK Post Type Creator" plugin by Reflection Media & Madalin Ungureanu (Version 1.0) - http://wordpress.org/extend/plugins/custom-post-type-creator/
The custom fields were created using the "Advanced Custom Fields" plugin by Elliot Condon (Version 3.4.3) - http://www.advancedcustomfields.com/
This topic is now archived. It is frozen and cannot be changed in any way.