Best way to get a 'featured image' for venue
WordPress Event Management, Calendars & Registration › Forums › General Question › Best way to get a 'featured image' for venue
This topic contains 11 replies, has 2 voices, and was last updated by Andrew 11 years, 10 months ago.
-
AuthorPosts
-
January 31, 2013 at 12:06 pm #3186
Hi guys
I’m looking for a way to incoporate a ‘featured image’ type image for each venue.
I need my venue page to have this image, which will also be used elsewhere in the site in my venue lists.
Any help would be greatly appreciated…
AndrewJanuary 31, 2013 at 4:39 pm #3187Hi Andrew,
Unfortunately venue images are not natively supported by EO ( or WP – venues are taxonomy terms) – though this feature is likely to be included in the premium add-on (currently in development, due for release in March).
However, you can add this feature yourself – Event Organiser provides hooks and API functions that allow you to add custom metaboxes to the venue admin page ( see this example ). You could use that to store the thumbnail as venue meta (much in the same way WordPress does) (either the src of the image, or its thumbnail ID and implement WP’s media uploader).
Hope that helps!
Stephen HarrisFebruary 1, 2013 at 11:01 am #3202Hi Stephen,
thanks for the reply.
The metabox is added to the venue page fine, however I am unable to save any data added to the text field.
Adding information, then clicking ‘updated venue’ just brings up a warning “are you sure you want to do this? try again”.
At which point I’m directed back to the venue page and the information hasn’t been saved in the metabox.
Any ideas why this is happening?
AndrewFebruary 1, 2013 at 11:17 am #3206Hi Andrew,
Yup – this is because the nonce is not validating. Its a simple security check to ensure you weren’t tricked into performing that action (e.g. by someone getting you to click a link).
In the metabox you should have something like:
//Remember to use nonces! wp_nonce_field( 'my_venue_meta_save', 'my_plugin_nonce_field' )
Then when you save the data you check the generated nonce:
check_admin_referer( 'my_venue_meta_save', 'my_plugin_nonce_field' );
(I’ve noticed in the example I linked to these didn’t match up – which is why you’re getting the ‘Are you sure’ message – I’ve updated the page now.)
Stephen HarrisFebruary 1, 2013 at 11:23 am #3208Wow, thanks for the quick reply.
I still get the message however…
Below is exactly what I put into my functions.php. (I haven’t yet changed any variable names etc)
–
// Add additional meta boxes for Venue pages
add_action(‘add_meta_boxes’,’my_add_metabox’);
function my_add_metabox(){
add_meta_box(‘my_id’,’My Title’, ‘my_metabox_callback’, ‘event_page_venues’, ‘side’, ‘high’);
}
function my_metabox_callback( $venue ){
//Metabox’s innards:
$time = eo_get_venue_meta($venue->term_id, ‘_opening_times’,true);//Remember to use nonces!
wp_nonce_field( 'my_venue_meta_save', 'my_plugin_nonce_field' );
?><label> Opening times:</label>
<input type="text" name="my_opening_time" value="<?php echo esc_attr($time);?>" >
<?php}
add_action (‘eventorganiser_save_venue’,’my_save_venue_meta’);
function my_save_venue_meta( $venue_id ){//Check permissions
$tax = get_taxonomy( 'event-venue');
if ( !current_user_can( $tax->cap->edit_terms ) )
return;//Check nonce
check_admin_referer('my_venue_meta_save_'.$venue_id, 'my_plugin_nonce_field');//Retrieve meta value(s)
$value = $_POST['my_opening_time'];//Update venue meta
eo_update_venue_meta($venue_id, '_opening_times', $value);
return;}
AndrewFebruary 1, 2013 at 11:26 am #3210The values you give to
wp_nonce_field
do not match the values you give tocheck_admin_referer
– see the example I linked to again, because I’ve corrected this error.Stephen HarrisFebruary 1, 2013 at 11:31 am #3211Awesome… thanks so much!
AndrewFebruary 1, 2013 at 12:11 pm #3213Hi…
Sorry I’m back again!
I’m struggling to retrieve the meta now…. How do I target “this” venue ID?
For example…. this works…
<?php
$display_image = eo_get_venue_meta(34, '_venue_featured_image', true);
echo $display_image;
?>
However, I don’t want to hard code the venue ID, i need to get the ID of whichever venue is being displayed?
i.e. what should replace $venue_id
apologies for being a pain!
AndrewFebruary 1, 2013 at 12:14 pm #3214No worries – I think what you’re after is
eo_get_venue()
. You can pass it the event ID (of whose venue you want) or if its ‘inside the loop’ then you ommit the event ID and it will use the current event.If you are using this in the venue template page then you can use
get_queried_object_id()
to get the venue ID.Stephen HarrisFebruary 1, 2013 at 4:26 pm #3216Again, thanks!
I have pretty much everything working now, apart from one thing.
I have created a page which is a ‘venue list’, which aims to display the image, address and postcode.
I can retrieve and display the address/postcode fine, but don’t know how i can reference the venue meta for the image within this function:
$venue_id appears to be empty!?<?php
$venues = eo_get_the_venues();
$venue = $venues[0];
$venue_id = $venue->venue_id;
$venue_name = $venue->name;
$venue_slug = $venue->slug;$venue_address = $venue->venue_address; $venue_postcode = $venue->venue_postal; $venues = eo_get_venues(); if( $venues ){ echo '<ul>'; foreach($venues as $venue): echo '<li>'; echo '<a href="http://www.festivalne.com/development/events/venues/'.esc_html($venue->slug).'">'.esc_html($venue->name).'</a></li>'; echo esc_html($venue->venue_address); echo esc_html($venue->venue_postal); $display_image = eo_get_venue_meta($venue_id, '_venue_featured_image', true); echo '<img src="'.$display_image.'" alt="'.esc_html($venue->name).'" />' ; endforeach; echo '</ul>'; }
?>
I think this is because I’m trying to get the venue information without it being related to an event…
Is there a function I’m using wrong?
Thanks again! Great plugin, will definitely upgrade to the premium version when released.
AndrewFebruary 1, 2013 at 4:32 pm #3217Hi Andrew,
The venue object is actually a taxonomy term object, so
$venue->venue_id
doesn’t exist. In any case you should avoid touching the venue object directly and use the available API (list available here)The only thing you’lll need to get is the term ID:
$venue_id = (int) $venue->term_id;
(Most of the venue API functions will allow yout pass the venue slug as well – so you need to make sure when giving them an ID that its cast as an integer.)
Stephen HarrisFebruary 4, 2013 at 11:44 am #3296Well, wasn’t that simple!
Again… thanks… you’re awesome!
Andrew -
AuthorPosts