Help needed for displaying past events(archive) of a specific category

Home Forums Calendar Products Events Calendar PRO Help needed for displaying past events(archive) of a specific category

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #47649
    Prateek
    Participant

    Hi,
    I have created a page to display past events(archive) of a specific category. The category part works fine though the events which has already passed is listing along with the upcoming. Please check my code
    $arg = array(
    ‘post_status’=>’publish’,
    ‘post_type’=>array(TribeEvents::POSTTYPE),
    ‘posts_per_page’=>40,
    //order by startdate from newest to oldest
    ‘eventDisplay’=>’past’,
    ‘order’=>’DESC’,
    //query events by category
    ‘tax_query’ => array(
    array(‘taxonomy’ => ‘tribe_events_cat’, ‘field’ => ‘slug’, ‘terms’ => ‘150-anniversary’, ‘operator’ => ‘IN’),));
    $get_posts = null;
    $get_posts = new WP_Query();
    $get_posts->query($args);
    if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>

    Any suggestion where i am wrong. you can check the output here http://www.rkmkhar.org/150th-anniversary-events-archive/

    Thanks in advance
    Pratz

    #47720
    Jonah
    Participant

    Hi Pratz,

    ‘eventDisplay’ is not a valid arg you can pass to WP_Query. Only what you see here is: http://codex.wordpress.org/Class_Reference/WP_Query – you can pass in custom field args to target a specific date range with WP_Query. For example: http://chopapp.com/#ktei2z6e

    Alternatively you can use tribe_get_events() instead of WP_Query and pass in the eventDisplay arg. We’ve got some examples here: https://theeventscalendar.com/support/documentation/the-events-calendar-template-tags-general-functions/#functiontribe_get_events

    I hope that helps but let me know if you have any questions.

    – Jonah

    #47959
    Prateek
    Participant

    Hi Jonah,
    The New code works fine form me except for new issue, the ‘orderby’=>’DESC’, is not working. It will be great if you can tell me where i am wrong

    Here is my code:

    global $post;
    $current_date = date(‘j M Y’);
    $end_date = date(‘j M Y’, strtotime(‘-730 days’));

    $get_posts = tribe_get_events(
    array(
    ‘start_date’=>$current_date,
    ‘end_date’=>$end_date,
    ‘posts_per_page’=>-1,
    ‘orderby’=>’DESC’,
    ‘tax_query’=> array(
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘150-anniversary’
    )
    )
    ) );

    foreach($get_posts as $post) { setup_postdata($post); ?>

    #48068
    Jonah
    Participant

    Hi Prateek,

    You cannot use the orderby arg with tribe_get_events() because it uses it’s own sorting functions to sort events by date ASC. If you want to use orderby you’ll need to use WP_Query and then set your date ranges appropriately.

    I hope that helps!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Help needed for displaying past events(archive) of a specific category’ is closed to new replies.