How to display the past events in one of the category?

I my project I have the events page where it display all the upcoming events according to the dates. But my client needs to have one more category called "Past events", where all the past events should be stored there. So that when the event expires it has to go that particular past event category. Can anyone suggest me how to achieve this?

Help needed.

Topic categories events Wordpress

Category Web


you would need to use the date query:

$args = array (
   'cat' => '1234', // if category being used
   'post_type' => 'events', // if custom post type
   'paged' => get_query_var('paged'),
   'order' => 'DESC',
   'paged' => $paged,
   'date_query' => array( // this is the thing you need
     array(
       'before'    => array( // this is 'before today'...
         'year'  => date('Y'),
         'month' => date('m'),
         'day'   => date('d')
        ),
       'inclusive' => true,
     ),
    ),

    );
   $past_events = new WP_Query($args);

category, post type, and date in which you deem to be 'past' can be manipulated there.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.