Q:

Wordpress - only show posts where custom date and time meta is equal to or greater than right now

I'm querying a custom post type, 'schedule', and sorting the posts by a custom meta field, '_broadcast_date' to try and create a tv guide sort of thing. 
Here's the code from my plugin that registers the post type and custom meta:
/** Register Schedule Post Type */
add_action( 'init', 'hiblio_pt_schedule_init' );
function hiblio_pt_schedule_init() {
    $labels = array(
    'name'               => _x( 'Scheduled Programmes', 'post type general name', 'hbl-plugin' ),
    'singular_name'      => _x( 'Scheduled Programme', 'post type singular name', 'hbl-plugin' ),
    'menu_name'          => _x( 'Scheduled Programmes', 'admin menu', 'hbl-plugin' ),
    'name_admin_bar'     => _x( 'Scheduled Programme', 'add new on admin bar', 'hbl-plugin' ),
    'add_new'            => _x( 'Add New', 'scheduled-programme', 'hbl-plugin' ),
    'add_new_item'       => __( 'Add a Programme to the Schedule', 'hbl-plugin' ),
    'new_item'           => __( 'New Scheduled Programme', 'hbl-plugin' ),
    'edit_item'          => __( 'Edit Scheduled Programme', 'hbl-plugin' ),
    'view_item'          => __( 'View Scheduled Programme', 'hbl-plugin' ),
    'all_items'          => __( 'Scheduled Programmes', 'hbl-plugin' ),
    'search_items'       => __( 'Search Scheduled Programmes', 'hbl-plugin' ),
    'parent_item_colon'  => __( 'Parent Scheduled Programmes:', 'hbl-plugin' ),
    'not_found'          => __( 'No Scheduled Programmes found.', 'hbl-plugin' ),
    'not_found_in_trash' => __( 'No Scheduled Programmes found in Trash.', 'hbl-plugin' )
    );

    $args = array(
    'labels'             => $labels,
    'description'        => __( 'Description.', 'hbl-plugin' ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => 'hbl-admin',
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'schedule' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
    'taxonomies'           => array( 'hbl-categories' ),
    'register_meta_box_cb' => 'add_schedule_metaboxes'
    );

    register_post_type( 'schedule', $args );
}

/** Custom Meta for Schedule Post Type */
function add_schedule_metaboxes(){
    add_meta_box('hbl_schedule_meta', 'Programme Details', 'hbl_schedule_meta', 'schedule', 'normal', 'high');
}

/*** Schedule Meta Box */
function hbl_schedule_meta() {
    global $post;

    echo '<input type="hidden" name="schedulemeta_noncename" id="schedulemeta_noncename" value="' . 
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

    $broadcastDate = get_post_meta($post->ID, '_broadcast_date', true);
    echo '<label for="_broadcast_date">Broadcast Date</label><input type="date" name="_broadcast_date" value="' . $broadcastDate  . '" class="widefat" /><br /><br />';

    $broadcastTime = get_post_meta($post->ID, '_broadcast_time', true);
    echo '<label for="_broadcast_time">Broadcast Time</label><input type="time" name="_broadcast_time" value="' . $broadcastTime  . '" class="widefat" />';
}

/** Save schedule meta */
function hbl_save_schedule_meta($post_id, $post) {

    if ( !wp_verify_nonce( $_POST['schedulemeta_noncename'], plugin_basename(__FILE__) )) {
    return $post->ID;
    }

    if ( !current_user_can( 'edit_post', $post->ID )) {
    return $post->ID;
    }

    $schedule_meta['_broadcast_date'] = $_POST['_broadcast_date'];
    $schedule_meta['_broadcast_time'] = $_POST['_broadcast_time'];

    foreach ($schedule_meta as $key => $value) {
    if( $post->post_type == 'revision' ) return;
    $value = implode(',', (array)$value);
    if(get_post_meta($post->ID, $key, FALSE)) {
        update_post_meta($post->ID, $key, $value);
    } else {
        add_post_meta($post->ID, $key, $value);
    }
    if(!$value) delete_post_meta($post->ID, $key);
    }

}

add_action('save_post', 'hbl_save_schedule_meta', 1, 2);

Here's the code from my page template:
<?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( 'template-parts/content', 'page' ); ?>

    <?php
        global $post;
        $args=array(
          'post_type' => 'schedule',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1,
          'orderby' => '_broadcast_date',
          'order' => 'ASC'
        );
        $schedule_query = null;
        $schedule_query = new WP_Query($args);
        if( $schedule_query->have_posts() ) {
            while ($schedule_query->have_posts()) : $schedule_query->the_post(); ?>
                <div class="scheduleItem">
                    <div class="scheduleItemImage" style="background-image: url(<?php if ( has_post_thumbnail() ) {
                        echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                        } else {
                        echo get_template_directory_uri().'/images/rewindBlank.jpg';
                        }
                    ?>)"></div>
                    <div class="scheduleItemInfoWrapper">
                        <h2><?php the_title(); ?></h2>
                        <div class="scheduleItemContent">
                            <?php echo the_content(); ?>
                        </div>
                        <div class="scheduleItemDetails">
                            <span class="scheduleItemDate"><?php echo get_post_meta( $post->ID, '_broadcast_date', true).'</span> @ <span class="scheduleItemTime">'.get_post_meta( $post->ID, '_broadcast_time', true)  ?></span>
                        </div>
                    </div>
                </div>

            <?php endwhile;
        }
        wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

<?php endwhile; // End of the loop. ?>  

What I'd like to do is alter the query somehow so that it will only return posts where the _broadcast_date and _broadcast_time meta is in the future, i.e. only upcoming broadcasts will be displayed. Any ideas?

A:

You can use a meta_query like so: (Not tested, may need revision)
$args=array(
    'post_type' => 'schedule',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1,
    'orderby' => '_broadcast_date',
    'order' => 'ASC',
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => '_broadcast_date',
            'value' => date('Y-m-d'),
            'compare' => '>=',
            'type' => 'DATE'
        ),
        array(
            'key' => '_broadcast_time',
            'value' => date('H:i'),
            'compare' => '>=',
            'type' => 'TIME'
        ),
    )
);
$schedule_query = new WP_Query($args);

EDIT: Live long, vote often :D

