• I have set up a Custom Post Type called “Events”. I set the event date in a Custom Field called “date__time.” What I’d like to do, is on my Events landing page, display only those events that are in the future based on the date entered in the Custom Field.

    After digging around, here’s what I’ve come up with:

    <?php $events = new WP_Query( 'post_type=events&posts_per_page=-1&meta_key=date__time&orderby=meta_value&meta_compare=>=&meta_value='.time().'&order=ASC' ); 
    
    if ($events->have_posts()) : while ($events->have_posts()) : $events->the_post(); ?>

    I have set up two events, one in the past and one in the future. The problem is, both events are showing.

    I have read something about storing the value of the Custom Field (date__time – in the above code) as a unix time stamp, but I have no idea how to do that or why (or where to do that).

    Any help would be greatly appreciated.
    Many thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter psnepsts

    (@psnepsts)

    Hey folks,

    Still not having any luck with this. Can anyone point me in the right direction?

    Thread Starter psnepsts

    (@psnepsts)

    It’s been over a week now, and I’m stumped as to how to accomplish this. Seems like a simple thing to do. I’m able to sort by this meta_value, but what I really want to do is display only those that are in the future. In pseudo-code, I want to:

    Search all posts with the post type "events"
    Get the current date
    Compare it to the date value in "date__time" (custom field)
    If the value of "date__time" is in the past, do nothing
    If the value of "date__time" matches the current date, or is in the future, display three of them
    Sort them from ascending (date closest to today first)

    Folks, any help with this would be very much appreciated.

    Sarah

    (@sazzlemajazzle)

    Hi, I’m trying to do something very similar – have you had any luck in trying to figure this out?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display future events by querying a Custom Field 'date' entry’ is closed to new replies.