• I would like to code up a custom date field for events in a format that allows DB queries like
    SELECT * FROM posts WHERE event_date < today

    I have written a jquery date selector and a piece of PHP to convert this date to a UNIX timestamp. Can I now do date based db queries on it?

    function save_price(){
    	global $post;
    	// Store date in UNIX timestamp format with strtotime()
    	update_post_meta($post->ID, "event_date", strtotime($_POST["event_date"]));
    	}
Viewing 1 replies (of 1 total)
  • Thread Starter charleyramm

    (@charleyramm)

    $args = array( 	'post_type' => 'gig',
    				'orderby' => 'meta_value',
    				'meta_key' => 'event_date',
    				'meta_value' => time(),
    				// is event_date >= time()
    				'meta_compare' => '>=');
    $loop = new WP_Query( $args );
    if ($loop->have_posts()){
    	while ( $loop->have_posts() ) { $loop->the_post();?>
Viewing 1 replies (of 1 total)
  • The topic ‘Store custom field event_date as a db DATE’ is closed to new replies.