The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Date sorting in Verve Meta Boxes (3 posts)

  1. circleabby
    Posted 5 years ago #

    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>
    		$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>
    		$event_query = $temp;  //reset back to original query


  2. Taylor Baybutt
    Posted 5 years ago #

    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.

  3. Taylor Baybutt
    Posted 5 years ago #

    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.


Topic Closed

This topic has been closed to new replies.

About this Topic