SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Get "next event" custom field within loop?

    Hi

    Background:
    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

    The problem:
    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

    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...

    PHP Code:
    <!-- 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)); ?>
        <p>
            <?php echo date('l jS M Y'strtotime($datearray['day'] ."-"$datearray['month'] ."-"$datearray['year'])); ?><br/>
            <strong><?php the_title(); ?></strong>
        </p>
        <?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!)

  2. #2
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/...-type-creator/

    The custom fields were created using the "Advanced Custom Fields" plugin by Elliot Condon (Version 3.4.3) - http://www.advancedcustomfields.com/


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •