• Our site has an upcoming events box that pulls in post titles as the upcoming events with Location and Date/Time info pulled in via boxes created using Verve Meta Boxes. I couldn’t use the Date field type for the date info, as it doesn’t support date ranges but only single dates. So, we set up the Date/Time field as a text entry. Doing so makes the post date the date used for sorting the events instead of the event date. I’m wondering if I could set all post dates to the event dates, and have even the ones set in the future appear in the list?

    Here’s the code:

    <table id="ma_events">
    	<tr class="toprow"><td class="details">Details</td><td class="location">Location</td><td class="date_time">Date/Time</td></tr>
    	<?php
    		$temp = $event_query;  // assign orginal query to temp variable for later use
    		$event_query = null;
    		$event_query = new WP_Query('cat=25,20&posts_per_page=5&orderby=date&order=asc');
    		if(have_posts()) :
    			while($event_query->have_posts()) : $event_query->the_post();
    	?>
    	<tr class="eventrow">
    		<td><a>" rel="bookmark" title="Read more — <?php the_title_attribute(); ?>"><?php the_title(); ?></a></td>
    		<td><?php echo get_post_meta($post->ID, 'location', true); ?></td>
    		<td><?php echo get_post_meta($post->ID, 'date_time', true); ?></td>
    	</tr>
    	<?php
    		endwhile;
    		endif;
    		$event_query = $temp;  //reset back to original query
    	?>
    </table>

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am struggling with this to. We need to do a meta_compare against the current time in the query. For past dates, it would be something like this.

    query('showposts=20&post_type=show&meta_key=date&orderby=meta_value&meta_compare=<=&meta_value=' . time() . '&order=DESC' );

    its not working, i think, because the way that Verve saves dates. The date needs strtotime() to convert it but I’m not sure how to go about doing that within a query. If you haven’t solved this, try this plugin: http://matth.eu/wordpress-date-field-plugin it works but the interface for setting the date on the backend is not as client-friendly as Verve’s.

    Let me know if you found a solution for Verve.

    ok, that was kind of easy once I articulated the problem. This should achieve what you want:

    query('&meta_key=date&orderby=meta_value&meta_compare=<=&meta_value=' . date("Y-m-d H:i:s", time()) . '&order=DESC' )

    just change meta_key=date to meta_key=“your verve meta box key”

    this function will show expired events, change the ‘<‘ to ‘>’ for upcoming events.

    ENJOY!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Date sorting in Verve Meta Boxes’ is closed to new replies.