adding extra fields to venue meta / $address_fields
WordPress Event Management, Calendars & Registration › Forums › General Question › adding extra fields to venue meta / $address_fields
This topic contains 18 replies, has 3 voices, and was last updated by Stephen Harris 8 years, 10 months ago.
-
AuthorPosts
-
July 9, 2015 at 6:39 pm #17818
Hi, i managed to disable and add extra fields in the backend for the event meta, but not able to store the value. i need two extra fields (url and Facebook url) and added/disabled them like this:
add_filter( ‘eventorganiser_venue_address_fields’, ‘my_callback_function’, 10, 1 );
function my_callback_function( $address_fields ){$address_fields = array( '_address'=> __('Address','eventorganiser'), '_city'=> __('City','eventorganiser'), //'_state'=> __('State / Province','eventorganiser'), '_postcode'=> __('Post Code','eventorganiser'), '_url'=> __('URL','eventorganiser'), //'_country'=> __('Country','eventorganiser'), ); //Change first value and return it return $address_fields;
};
besides this i am trying to add a radio selection to give categories to the venues (bar, club, cinema), right now jam doing this with custom fields – but thats not comfortable.
tmksr
July 14, 2015 at 12:05 am #17855Hi tmksr,
Apologies for the delay in getting back to you.
Does this need to be in the same metabox as the map?
If not, you can follow the instructions given here: http://wp-event-organiser.com/documentation/developers/venue-meta-data-and-metaboxes/ to add a custom metabox with any type of fields. The documentation details on how to save the provided data too.
Stephen Harris
July 15, 2015 at 4:49 pm #17900thx for your respond, no it hasn’t to be in the metabox. your solution is working fine for me with the url – but iam having trouble in getting multiple values (bar,club,cinema) from the array – i only get the first one.
tmksr
July 15, 2015 at 6:02 pm #17902If you’re custom field can have multiple values you’ll want to pass
false
as the third argument ineo_get_venue_meta()
. Then it will return an array.(More details can be found here: http://codex.wp-event-organiser.com/function-eo_get_venue_meta.html)
Stephen Harris
July 17, 2015 at 6:15 pm #17931thanx so far!
i get the multiple values, but right now can’t update them all via :
eo_update_venue_meta($venue_id, ‘_opening_times’, $value);sorry for that many questions – iam not quite familiar with metaboxing
and thanx for the support!//Retrieve meta value(s)
$value = $_POST[‘my_opening_time’];//Update venue meta
eo_update_venue_meta($venue_id, ‘_opening_times’, $value);
return;PS: the link is broken in documentation http://codex.wp-event-organiser.com/function-eo_update_venue_meta/.html
tmksr
July 17, 2015 at 7:49 pm #17933Thanks! I’ll fix that link.
To update multiple values you can do the following. There are two ways of doing this: determine the difference between the existing and new values for the key, and add/remove values as appropriate. You can do that with
eo_add_venue_meta()
andeo_delete_venue_meta)
-using the third argument in the latter to specify which value should be deleted.Alternatively, the lazy/easy way is to delete all values for the venue and start again:
$values = $_POST['key_with_multiple_values']; eo_delete_venue_meta( $venue_id, 'key_with_multiple_values' ); foreach ( $values as $value ) { eo_add_venue_meta( $venue_id, $value ); }
Codex links
Stephen Harris
July 17, 2015 at 8:13 pm #17934thanx, but this is going to delete all my values at once – i am somehow misunderstanding how it works. my code looks like below right now. Each venue has 1 to 3 fixed values (bar, cinema, club) stored in the custom field “venue_kategorie” …
add_action('add_meta_boxes','my_add_metabox'); function my_add_metabox(){ add_meta_box('my_id','Venue Kategorie', 'my_metabox_callback', 'event_page_venues', 'advanced', 'high'); } function my_metabox_callback( $venue ){ //Metabox's innards: $time = eo_get_venue_meta($venue->term_id, 'venue_kategorie'); $time2 = eo_get_venue_meta($venue->term_id, 'venue_kategorie', false); $time3 = eo_get_venue_meta($venue->term_id, 'venue_kategorie', false); //Remember to use nonces! wp_nonce_field('my_venue_meta_save', 'my_plugin_nonce_field' ); ?> <label></label> <input type="text" name="my_opening_time" value="<?php echo esc_attr($time);?>" > <input type="text" name="my_opening_time2" value="<?php echo esc_attr($time2[1]);?>" > <input type="text" name="my_opening_time3" value="<?php echo esc_attr($time3[2]);?>" > <?php } add_action ('eventorganiser_save_venue','my_save_venue_meta'); function my_save_venue_meta( $venue_id ){ //If our nonce isn't present just silently abort. if( !isset( $_POST['my_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( 'my_venue_meta_save', 'my_plugin_nonce_field' ); //Retrieve meta value(s) //$value = $_POST['my_opening_time']; $values = $_POST['venue_kategorie']; eo_delete_venue_meta( $venue_id, 'venue_kategorie' ); foreach ( $values as $value ) { eo_add_venue_meta( $venue_id, $value ); } //Update venue meta eo_update_venue_meta($venue_id, 'venue_kategorie', $value); return; }
tmksr
July 17, 2015 at 10:21 pm #17935Here’s how I’d do it:
function my_metabox_callback( $venue ){ //Metabox's innards: $cats = eo_get_venue_meta($venue->term_id, 'venue_kategorie', false ); $cats = array_merge( array( 0 => '', 1 => '', 2 => '' ), $cats ); //Remember to use nonces! wp_nonce_field('my_venue_meta_save', 'my_plugin_nonce_field' ); ?> <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[0]);?>" > <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[1]);?>" > <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[2]);?>" > <?php } add_action ('eventorganiser_save_venue','my_save_venue_meta'); function my_save_venue_meta( $venue_id ){ //If our nonce isn't present just silently abort. if( !isset( $_POST['my_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( 'my_venue_meta_save', 'my_plugin_nonce_field' ); //Retrieve meta value(s) $values = $_POST['venue_kategorie']; eo_delete_venue_meta( $venue_id, 'venue_kategorie' ); foreach ( $values as $value ) { eo_add_venue_meta( $venue_id, $value ); } }
The
eo_delete_venue_meta( $venue_id, 'venue_kategorie' )
deletes all the venue’s existing categories, before adding the categories it currently has. This does mean you’re doing this ever time the venue is updated, so a more efficient solution would be to determine which categories you need to add / remove.I’ve not checked the above, but it should work.
Stephen Harris
July 21, 2015 at 7:32 pm #17996Hi Stephen,
thanks a lot for your support . Unfortunately it still is not showing my already stored values in the new fields, and on trying to update the post it clears them all. Even if i enter new values they will not be stored – everything got cleared from the custom field. i used your code as follows in my function.inc . – iam getting it wrong!
in general the categories will be given when a new venue is created and will not change anymore, so its not a problem.add_action('add_meta_boxes','my_add_metabox'); function my_add_metabox(){ add_meta_box('my_id','Wähle Venue Kategorie', 'my_metabox_callback', 'event_page_venues', 'advanced', 'high'); } function my_metabox_callback( $venue ){ //Metabox's innards: $cats = eo_get_venue_meta($venue->term_id, 'venue_kategorie', false ); $cats = array_merge( array( 0 => '', 1 => '', 2 => '' ), $cats ); //Remember to use nonces! wp_nonce_field('my_venue_meta_save', 'my_plugin_nonce_field' ); ?> <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[0]);?>" > <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[1]);?>" > <input type="text" name="kategorie[]" value="<?php echo esc_attr($cats[2]);?>" > <?php } add_action ('eventorganiser_save_venue','my_save_venue_meta'); function my_save_venue_meta( $venue_id ){ //If our nonce isn't present just silently abort. if( !isset( $_POST['my_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( 'my_venue_meta_save', 'my_plugin_nonce_field' ); //Retrieve meta value(s) $values = $_POST['venue_kategorie']; //eo_delete_venue_meta( $venue_id, 'venue_kategorie' ); foreach ( $values as $value ) { eo_add_venue_meta( $venue_id, $value ); } //Update venue meta eo_update_venue_meta($venue_id, 'venue_kategorie', $value); return; }
tmksr
July 23, 2015 at 8:14 am #18035Sorry, there some errors in my previous post. I’ve updated your post with the corrections:
Changes:
- Replaced
$_POST['venue_kategorie']
with $_POST[‘kategorie’] - Uncommented
eo_delete_venue_meta( $venue_id, 'venue_kategorie' )
, - Corrected
eo_add_venue_meta()
updated call - Removed
eo_update_venue_meta()
call.
Also, replace
$cats = array_merge( array( 0 => '', 1 => '', 2 => '' ), $cats );
with
$cats = $cats + array( 0 => '', 1 => '', 2 => '' );
(I’ve not included that below), Here’s the updated part:
add_action ('eventorganiser_save_venue','my_save_venue_meta'); function my_save_venue_meta( $venue_id ){ //If our nonce isn't present just silently abort. if( !isset( $_POST['my_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( 'my_venue_meta_save', 'my_plugin_nonce_field' ); //Retrieve meta value(s) $values = $_POST['kategorie']; eo_delete_venue_meta( $venue_id, 'venue_kategorie' ); foreach ( $values as $value ) { eo_add_venue_meta( $venue_id, 'venue_kategorie', $value ); } return; }
Stephen Harris
July 23, 2015 at 8:25 pm #18040thanks a lot – its working! great support!!
tmksr
July 23, 2015 at 8:47 pm #18041mmh only problem is – i can’t publish new venues anymore?!!! the publish button is gone!
tmksr
July 23, 2015 at 9:37 pm #18042Can you not see the ‘save’ metabox?
Stephen Harris
July 24, 2015 at 6:33 pm #18060Correct, if i create a new venue – there is no “save” metabox! All other boxes are minified and not expandable. The content-box has no menu-icon-bar etc.
tmksr
August 3, 2015 at 8:49 pm #18258Hi, I sent you an e-mail last week regarding this, did you get it?
Stephen Harris
- Replaced
-
AuthorPosts