0

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>

1 Answer 1

0

Replace $today = date('Ymd') with

$hour = 0;
$minute = 0;
$second = 0;
$month = (is_month()) ? get_the_date('m') : 1;
$day = (is_day()) ? get_the_date('d') : 1;
$year = get_the_date('Y');

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

$search_date = date('Ymd', $timestamp);

// echo $search_date;

In your query, replace 'value' => $today, with

 'value' => $search_date,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.