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

admin2025-01-08  6

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.

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.

Share Improve this question asked Apr 6, 2016 at 7:33 RiteshRitesh 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267977a1237.html

最新回复(0)