Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

svsdnb on "Query Date Array To Display Future Events Only"

$
0
0

Turns out I just had to convert this via functions.php to unix timestamp and it worked.

functions.php

function custom_unixtimesamp ( $post_id ) {
    if ( get_post_type( $post_id ) == 'events' ) {
	$startdate = get_post_meta($post_id, 'event_date_begins', true);

		if($startdate) {
			$dateparts = explode('/', $startdate);
			$newdate1 = strtotime(date('d.m.Y H:i:s', strtotime($dateparts[1].'/'.$dateparts[0].'/'.$dateparts[2])));
			update_post_meta($post_id, 'unixstartdate', $newdate1  );
		}
	}
}
add_action( 'save_post', 'custom_unixtimesamp', 100, 2);

then query

$today = time();	

	$args = array(
        'post_type' => 'events',
	'post_status' => 'publish',
	'posts_per_page' => '10',
	'meta_query' => array(
		array(
			'key' => 'unixstartdate',
			'compare' => '>=',
			'value' => $today,
			)
			),
	'meta_key' => 'event_date_begins',
	'orderby' => 'meta_value',
	'order' => 'ASC',
	'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
);

Viewing all articles
Browse latest Browse all 5527

Trending Articles