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.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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…

    Andrew
    #3187

    Hi 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 Harris
    #3202

    Hi 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?

    Andrew
    #3206

    Hi 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 Harris
    #3208

    Wow, 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;

    }

    Andrew
    #3210

    The values you give to wp_nonce_field do not match the values you give to check_admin_referer – see the example I linked to again, because I’ve corrected this error.

    Stephen Harris
    #3211

    Awesome… thanks so much!

    Andrew
    #3213

    Hi…

    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!

    Andrew
    #3214

    No 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 Harris
    #3216

    Again, 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-&gt;venue_address; 
      $venue_postcode = $venue-&gt;venue_postal; 
    
    
      $venues = eo_get_venues(); 
    
      if( $venues ){
           echo '&lt;ul&gt;'; 
           foreach($venues as $venue): 
    
            echo '&lt;li&gt;';
    
            echo '&lt;a href="http://www.festivalne.com/development/events/venues/'.esc_html($venue-&gt;slug).'"&gt;'.esc_html($venue-&gt;name).'&lt;/a&gt;&lt;/li&gt;';
            echo esc_html($venue-&gt;venue_address);
            echo esc_html($venue-&gt;venue_postal);
    
            $display_image = eo_get_venue_meta($venue_id, '_venue_featured_image', true); 
    
            echo '&lt;img src="'.$display_image.'" alt="'.esc_html($venue-&gt;name).'" /&gt;' ;
    
    
    
            endforeach; 
    
           echo '&lt;/ul&gt;';
       }
    

    ?>

    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.

    Andrew
    #3217

    Hi 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 Harris
    #3296

    Well, wasn’t that simple!

    Again… thanks… you’re awesome!

    Andrew
Viewing 12 posts - 1 through 12 (of 12 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.