Future events of one category

This topic contains 2 replies, has 2 voices, and was last updated by  Paksha Thullner 10 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8708

    A stupid question maybe … I tried a lot but I can’t get the future events only in the taxonomy-event-category template. I tried with WP Query but then I don’t succeed with filtering for 1 category. I would be happy with any hint.

    Paksha Thullner
    #8714

    Hi Paksha,

    If you want to general show only future events there is an option in Settings > Event Organiser > General.

    If you want to target (event) categories only, and the following to a utility plug-in / your theme’s functions.php:

    add_action( 'pre_get_posts', 'paksha_future_events_for_categories', 15 );
    function paksha_future_events_for_categories( $query ){
    
        if( $query->is_main_query() && is_tax( 'event-category' ) ){
               $query->set( 'showpastevents', false );
        }
    }

    (see documentation for is_tax(): http://codex.wordpress.org/Function_Reference/is_tax )

    For a specific category:

    add_action( 'pre_get_posts', 'paksha_future_events_for_categories', 15 );
    function paksha_future_events_for_categories( $query ){
    
        if( $query->is_main_query() && is_tax( 'event-category', 'my-cat-slug' ) ){
               $query->set( 'showpastevents', false );
        }
     }
    Stephen Harris
    #8722

    Thanks a lot. It works!

    Paksha Thullner
Viewing 3 posts - 1 through 3 (of 3 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.