Skip to main content
edited tags
Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459
Source Link

Display only upcoming events / Show all events when archive year is selected

I'm working on a wordpress site that will query only upcoming events (custom post type). I've figured out how to only display upcoming events but I would like to allow users to view Past Events when they click on the archives tab which I created using wp_get_archives. Right now when you select a archive year like '2013' it outputs the same query of 'upcoming events' but I want to out put all events in 2013. How do I so?

$today = date('Ymd');

$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$posts = new WP_Query(array(
    'post_type' => 'event',
    'post_status' => 'publish',
    'posts_per_page' => 5,
    'meta_key' => 'new_start_date',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'meta_query' => array(
        array(
            'key' => 'new_start_date',
            'compare' => '>=',
            'value' => $today,
            'type' => 'DATE'
        ),
    ),
    'paged' => $paged
));

<div class="my-pa_archive_post-year">
   <?php 
     $args = array(
        'type' => 'yearly',
        'limit'           => '',
        'format'          => 'html', 
        'before'          => '',
        'after'           => '',
        'show_post_count' => false,
        'echo'            => 1,
        'order'           => 'DESC',
        'post_type' => 'event',
      );
      wp_get_archives( $args );
    ?>
  </div>