Support

Account

Home Forums General Issues Using date picker to show dates in future on one page

Solving

Using date picker to show dates in future on one page

  • I’m trying to create a gig listing system.

    I’ve a custom post type ‘gigs’ and a date picker ‘event_start_date’, but want to only show future dates on one page and only previous dates in another.

    My trusty old using the post publish/scheduled used to work but I’m switching it up.

    I don’t want to select it between two dates, or at least would prefer not to, can anybody assist me, surely there is a simple query – a lot of the previous answers on here either didn’t work for me or were too complicated to figure out unfortunately – apologies for my ignorance.

  • Hi @duuuaaaane

    So you want two different queries? One where you’ll fetch all posts that has a value for event_start_date that is past todays date and one for al posts that is the same or ahead of todays date?

  • Hey Jonathan! Yep that’s what I’m trying to achieve!

  • Hi @duuuaaaane

    Sorry for the delay in a response!

    This code should either work out of the box or atleast get you rolling!

    
    <?php
    	
    //Make sure pagination works
    global $query_string;
    $args = wp_parse_args($query_string);
    if ( get_query_var('paged') ) {
    	$paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    	$paged = get_query_var('page');
    } else {
    	$paged = 1;
    }
    
    $today = date('Ymd');
    
    $old_args = array(
    	'post_type' => 'gigs',
    	'posts_per_page' => 10,
    	'paged' => $paged,
    	'meta_query' => array(
    		array(
    			'key' => 'event_start_date',
    			'value' => $today,
    			'compare' => '<',
    			'type' => 'date'
    		)
    	)
    );
    $old_gigs_query = new WP_Query($old_args);
    
    $new_args = array(
    	'post_type' => 'gigs',
    	'posts_per_page' => 10,
    	'paged' => $paged,
    	'meta_query' => array(
    		array(
    			'key' => 'event_start_date',
    			'value' => $today,
    			'compare' => '>=',
    			'type' => 'date'
    		)
    	)
    );
    $new_gigs_query = new WP_Query($old_args);
    	
    ?>
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.