• Resolved jbo.ciel

    (@jbociel)


    Hello,

    I have a question about custom fields for venues.

    I follow the guidelines here:
    https://wp-event-organiser.com/documentation/developers/venue-meta-data-and-metaboxes/

    I try to apply it for multi custom fields like that:

    /**
     * Add meta box to venue
     * @ https://wp-event-organiser.com/documentation/developers/venue-meta-data-and-metaboxes/
     * @since Custom
     **/
    add_action('add_meta_boxes','eo_custom_add_metabox');
    function eo_custom_add_metabox(){
          add_meta_box('eo_custom_metabox','Informations complémentaires', 'eo_custom_metabox_callback', 'event_page_venues', 'side', 'high');
    }
    function eo_custom_metabox_callback( $venue ){
        //Metabox's innards:
        $time = eo_get_venue_meta($venue->term_id, '_opening_times',true);
        $venue_phone = eo_get_venue_meta($venue->term_id, '_venue_phone',true);
    
        //Remember to use nonces!
        wp_nonce_field('eo_custom_venue_meta_save', 'eo_custom_plugin_nonce_field' );
        ?>
        <label> Opening times:</label>
        <input type="text" name="eo_custom_opening_time" value="<?php echo esc_attr($time);?>" >
    	<label> T&eacute;l&eacute;phone:</label>
    	<i class="howto">avec l'indicatif: +33 pour la France</i>
    	<input type="text" name="eo_custom_venue_phone" value="<?php echo esc_attr($_venue_phone);?>" >
    	<br/>
    	<br/>
        <?php
    }
    
    add_action ('eventorganiser_save_venue','eo_custom_save_venue_meta');
    function eo_custom_save_venue_meta( $venue_id ){
    
        //If our nonce isn't present just silently abort.
        if( !isset( $_POST['eo_custom_plugin_nonce_field'] ) )
            return;
    
        //Check permissions
        $tax = get_taxonomy( 'event-venue');
        if ( !current_user_can( $tax->cap->edit_terms ) )
            return;
    
        //Check nonce
        check_admin_referer( 'eo_custom_venue_meta_save', 'eo_custom_plugin_nonce_field' );
    
        //Retrieve meta value(s)
        $value = $_POST['eo_custom_opening_time'];
        $value1 = $_POST['eo_custom_venue_phone'];
    
        //Update venue meta
        eo_update_venue_meta($venue_id,  '_opening_times', $value);
        eo_update_venue_meta($venue_id,  '_venue_phone', $value1);
        return;
    }

    The first input works well, but my custom doesn’t seem to be saved. I guess it’s a problem with nonce but i don’t understand which one.

    Thank you in advance for your help.

    jB

    https://www.ads-software.com/plugins/event-organiser/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    You’re displaying the phone number with

    <?php echo esc_attr($_venue_phone);?>

    but you are assigning it

    $venue_phone = eo_get_venue_meta($venue->term_id, '_venue_phone',true);

    (i.e. $venue_phone and $_venue_phone) Fix that, and you shouldn’t have any problems ??

    Thread Starter jbo.ciel

    (@jbociel)

    Hello Stephen,

    Sorry for this omission.
    Thank you for your help.

    Here is my final code:

    add_action('add_meta_boxes','eo_custom_add_metabox');
    function eo_custom_add_metabox(){
          add_meta_box('eo_custom_metabox','Informations compl&eacute;mentaires', 'eo_custom_metabox_callback', 'event_page_venues', 'side', 'high');
    }
    function eo_custom_metabox_callback( $venue ){
    
        //Metabox's innards:
        $_venue_phone = eo_get_venue_meta($venue->term_id, '_venue_phone',true);
        $_venue_url = eo_get_venue_meta($venue->term_id, '_venue_url',true);
        $_venue_facebook = eo_get_venue_meta($venue->term_id, '_venue_facebook',true);
        $_venue_googleplus = eo_get_venue_meta($venue->term_id, '_venue_googleplus',true);
        $_venue_twitter = eo_get_venue_meta($venue->term_id, '_venue_twitter',true);
    
        //Remember to use nonces!
        wp_nonce_field('eo_custom_venue_meta_save', 'eo_custom_plugin_nonce_field' );
    
        ?>
    		<label> T&eacute;l&eacute;phone:</label>
    		<i class="howto">avec l'indicatif: +33 pour la France</i>
    		<input type="text" name="eo_custom_venue_phone" value="<?php echo esc_attr($_venue_phone);?>" >
    		<br/>
    		<br/>
    		<label> Website:</label>
    		<i class="howto">https://www.exemple.fr</i>
    		<input type="text" name="eo_custom_venue_url" value="<?php echo esc_attr($_venue_url);?>" >
    		<br/>
    		<br/>
    		<label> Facebook profile URL:</label>
    		<i class="howto"></i>
    		<input type="text" name="eo_custom_venue_facebook" value="<?php echo esc_attr($_venue_facebook);?>" >
    		<br/>
    		<br/>
    		<label> Google+:</label>
    		<i class="howto"></i>
    		<input type="text" name="eo_custom_venue_googleplus" value="<?php echo esc_attr($_venue_googleplus);?>" >
    		<br/>
    		<br/>
    		<label> Identifiant Twitter:</label>
    		<i class="howto">sans le @</i>
    		<input type="text" name="eo_custom_venue_twitter" value="<?php echo esc_attr($_venue_twitter);?>" >
        <?php
    
    }
    
    add_action ('eventorganiser_save_venue','eo_custom_save_venue_meta');
    function eo_custom_save_venue_meta( $venue_id ){
    
        //If our nonce isn't present just silently abort.
        if( !isset( $_POST['eo_custom_plugin_nonce_field'] ) )
            return;
    
        //Check permissions
        $tax = get_taxonomy( 'event-venue');
        if ( !current_user_can( $tax->cap->edit_terms ) )
            return;
    
        //Check nonce
        check_admin_referer( 'eo_custom_venue_meta_save', 'eo_custom_plugin_nonce_field' );
    
        //Retrieve meta value(s)
        $value1 = $_POST['eo_custom_venue_phone'];
        $value2 = $_POST['eo_custom_venue_url'];
        $value3 = $_POST['eo_custom_venue_facebook'];
        $value4 = $_POST['eo_custom_venue_googleplus'];
        $value5 = $_POST['eo_custom_venue_twitter'];
    
        //Update venue meta
        eo_update_venue_meta($venue_id,  '_venue_phone', $value1);
        eo_update_venue_meta($venue_id,  '_venue_url', $value2);
        eo_update_venue_meta($venue_id,  '_venue_facebook', $value3);
        eo_update_venue_meta($venue_id,  '_venue_googleplus', $value4);
        eo_update_venue_meta($venue_id,  '_venue_twitter', $value5);
        return;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multi custom fields for venues’ is closed to new replies.