List Venues with upcoming events only

WordPress Event Management, Calendars & Registration Forums General Question List Venues with upcoming events only

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

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

    Hello,

    How do I list all venue names which have events that are currently happening or upcoming?

    I got following code to list events:

    <?php
    $venues = eo_get_venues('number=15'); 
    if( $venues ){
        echo '
      '; foreach($venues as $venue): $venue_id = (int) $venue->term_id; printf('%s', eo_get_venue_link($venue_id), esc_html($venue->name)); endforeach; echo ''; } ?>

    What should I add there?

    Thanks!

    Jukka Varis
    #17310

    Hi Jukka,

    There’s no argument that allows you to use eo_get_venues() to retrieve only venues with future events, you’d have to construct your own sql query for that. One way (although fairly inefficient) is to do check each venue in turn:

    foreach($venues as $venue): 
    
         $venue_id = (int) $venue->term_id;
         $future_events_at_venue = eo_get_events( array(
              'event_end_after' => 'now',
              'tax_query' => array(
                    array(
                       'taxonomy' => 'actor',
                       'field'    => 'term_id',
                       'terms'    => $venue_id,
                    ),
              ),
         ));
    
         if ( $future_events_at_venue ) {
              printf('%s', eo_get_venue_link($venue_id), esc_html($venue->name));
         }
    
    endforeach;
    
    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.