Displaying all venues
WordPress Event Management, Calendars & Registration › Forums › Report A Bug › Displaying all venues
This topic contains 9 replies, has 3 voices, and was last updated by Stephen Harris 11 years, 10 months ago.
-
AuthorPosts
-
December 17, 2012 at 6:32 am #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 AronsonDecember 17, 2012 at 11:28 am #2702Hi 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 HarrisDecember 17, 2012 at 6:34 pm #2711Thanks, 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 AronsonDecember 17, 2012 at 7:03 pm #2713It 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 HarrisDecember 18, 2012 at 2:59 am #2729Thanks,
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 AronsonDecember 18, 2012 at 3:54 am #2730Hi 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 HarrisDecember 18, 2012 at 5:35 pm #2738Hi 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.
LarryLarry AronsonDecember 19, 2012 at 3:13 am #2743Hi 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!
StephenStephen HarrisJanuary 19, 2013 at 11:30 am #3056Hi 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
DarioJanuary 19, 2013 at 1:49 pm #3057Hi 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 usingpre_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 -
AuthorPosts