Displaying all venues

This topic contains 9 replies, has 3 voices, and was last updated by  Stephen Harris 11 years, 3 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2699

    I’m trying to create a page listing all venues using the example found on http://wp-event-organiser.com/documentation/function/eo_get_venues/

      $venues = eo_get_the_venues(); 
    
      if( $venues ){
           echo ''; 
           foreach($venues as $venue): 
                echo ''.esc_attr($venue->venue_name).''; 
           endforeach; 
           echo '';
       }
    

    All I get are empty list items. Although the length of the list matches the number of venues defined, no names are fetched.

    I’m using the latest version of Event Organiser under WordPress 3.5.

    Note also, that the examples on the documentation page for the eo_get_venues() function use the depreciated function eo_get_the_venues() . I’ve tried the code with both function and neither works.

    Please advise.
    TIA.

    Larry Aronson
    #2702

    Hi Larry,

    Thanks for pointing this out. You’re right the documentation for that page is incorrect. I’ll update it now (I’m actually in the process of going through and improving documentation)

    Stephen Harris
    #2711

    Thanks, Stephen.

    Any clue why the name is not appearing?
    The name does appear in the title on the single venue page either.
    And, even though there’s a full address, the google map is set at 0 long, 0 lat.

    I’ve done some playing around and it seems that none of the venue object’s properties are present.
    However, This bit of code does seem to work:

          $venues = eo_get_venues(array('fields'=>'ids')); 
          if( $venues ) {
            echo '<ul>'; 
            foreach($venues as $venue_id): 
            echo '<li>' . $venue_id . '</li>'; 
            endforeach; 
            echo '</ul>';
          } 
    

    And, I should be able to use eo_get_venue_name(), eo_get_venue_slug(), etc., to get the other properties I need to build the venues display page my client wants, but I’d rather not have to rewrite all of your templates in this manner.

    Do you know if anyone has a “display all venues” page template?

    Larry

    Larry Aronson
    #2713

    It could be that the IDs are cast as strings (the output is straight from a native WordPress function). If you specifically cast the venue IDs as integers and pass them to the appropriate functions it should work.

    I’ve updated the documentation, the name of the venue is $venue->name not $venue->venue_name as originally indicated.

    As for a venues “display all venues” page template, see this gist: https://gist.github.com/3902494

    I shall update the eo_get_venues() function to ensure that the IDs are returned as integers. (you can follow progress on this ticket: https://github.com/stephenharris/Event-Organiser/issues/21).

    Let me know if that resolves things for you 🙂

    Stephen Harris
    #2729

    Thanks,

    That solves the problem with generating a page listing all venues. However, I found a new one for you.

    The reason the venue name, description and map info are missing from the header of a single venue page – e.g: http://example.com/venues/venue_slug is because in the template file; taxonomy-event-venue.php, on line 31, the function eo_get_venue_name() is called without any arguments. According to the documentation, it should then pick up the venue ID from the current event object — But there is no current event at that point; you’re outside the loop! You need to do this instead:

      $venue_id = get_queried_object_id()   // integer venue id
      echo eo_get_venue_name( $venue_id );
    

    Likewise with the calls to get the description and map info.

    Later on (lines 77, 78) in that template file’s loop, the call to eo_get_venue_name() works because the event object has been created by the call to the_post(). However, there’s no point in displaying the venue info there because it’s the same info for every event which has already been displayed in the page header and any venue link points to the current page.

    Despite these problems, I like this plugin a lot. I has the features and flexibility I want without too much overhead.

    Larry

    Larry Aronson
    #2730

    Hi Larry,

    The default templates work for me. Strictly speaking you don’t have to be inside the loop. Just the global $post needs to be pointing to an event. If the venue page is showing any events, then it will be, so the venue description and map are displayed.

    If they are no events then you don’t see the venue description / map (which are inside the have_posts() anyway).

    (This will be changing in 1.7 – since I plan to improve the default templates)

    Stephen Harris
    #2738

    Hi Stephen,

    For your consideration when you revise the templates:

    I would very much like to show the venue name and description when there are no scheduled events at that venue. My client is entering the URL of the venue in the description and, if there are no events, then I want to append the message: “Please visit venue_name‘s website for more information.” to the no-scheduled-events message.

    Perhaps you can add a note to the documentation saying that the default behavior of using the current event when no venue id is passed to the venue functions can only be relied upon when the global $post variable is pointing to an event. Otherwise, to be safe, pass the integer value of the venue id.

    Thanks.
    Larry

    Larry Aronson
    #2743

    Hi Larry,

    That’s exactly what I’m planning to do ;).

    Regarding the documentation, I’ll update it in 1.6.2 to make it explicitly clear that ‘current event’ means current event specified in global $post.

    Thanks!
    Stephen

    Stephen Harris
    #3056

    Hi guys, I’m a bit of a beginner when it comes to php and wordpress coding so please bare with me.

    So I currently have lots of venues that sometimes have upcoming events and sometimes don’t. When there are no upcoming events for a specific venue, then the eo_get_venue_name, eo_get_venue_address, etc functions don’t work which is kind of a bummer.

    From what I understand I should pass the event slug or id as a parameter (ie eo_get_venue_address(7); ). Is there a way to find the current URL / slug and feed it into here, or must I create a separate file for every one of my venues?

    The code that I’m currently using: http://cl.ly/MHG6

    Thanks

    Dario
    #3057

    Hi Dario,

    To get the venue ID when in the venue template, you can use get_queried_object_id() , e.g:

    $venue_id = get_queried_object_id();
    echo eo_get_venue_name( $venue_id );
    echo implode( ', ', array_filter( eo_get_venue_address( $venue_id ) ) );
    

    Also, in the template you use eo_get_events() this isn’t necessary as once you’ve arrived on the venue pages WordPress has already fetched the events (see the default templates – there is no query, just ‘the loop’). If you want to modify the query (e.g. in your template you list all future events not just 10 on each page) I’d suggest using pre_get_posts filter.

    This is more efficient in that you’re not performing a second query, and is less prone to bugs. So assuming you’re using something like the default template, you could do the following (in your functions.php, say)

      add_action( ' pre_get_posts',  'dario_modify_event_venue_query' );
      function dario_modify_event_venue_query( $query ){
            if ( $query->is_main_query() && is_tax( 'event-venue' ) ){
                  //This is the main query for the event venue page
                 $query->set( 'posts_per_page', -1 ); //Show all on one page
                 $query->set( 'event_start_after', 'today' ); //Show only future events
            }
      }
    

    Hope that helps!

    Stephen Harris
Viewing 10 posts - 1 through 10 (of 10 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.