Only Show Upcoming Events in Category Template?

WordPress Event Management, Calendars & Registration Forums General Question Only Show Upcoming Events in Category Template?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 9 years, 12 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15650

    Here’s the problem i’m having.
    I want to show ALL events in the calendar, past and present, but I want to only show upcoming events in my category template. But I can’t find a way to limit the existing category list, since it just uses the basic ‘have_posts’ and the ‘while ( have_posts() ) : the_post(); ‘

    Is there a way to show this without turning off the past events on the calendar itself?

    I’d like to keep using the template files, as they make the event list look how I want (a bit customized).

    My only alternative thought is to turn off past events in the settings, but then include them in the calendar shortcode. Is this possible??

    Thanks!

    Aaron Robb
    #15651

    Hi Aaron,

    You can turn it off in the settings – the calendar will display past/present/future events regardless.

    But should you wish to alter the query:

    add_action( 'pre_get_posts', 'alter_my_event_query', 'alter_my_event_query' );
    function alter_my_event_query( $query ){
    
          if( $query->is_main_query() && $query->is_tax( 'event-category' ) ){
               //Make changes here to $query
               //$query->set( 'event_start_after', 'now' );
          }
    }
    
    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.