Home › Forums › Calendar Products › Events Calendar PRO › Update single event meta data
- This topic has 6 replies, 2 voices, and was last updated 8 years, 9 months ago by
PHILLIPA.
-
AuthorPosts
-
June 16, 2017 at 2:00 am #1298996
PHILLIPA
ParticipantI’ve included an overwrite of single-event.php within my child theme. Within this file I retrieve a Tribe custom variable associated with each event:
$holder = $custom_fields[‘Places left’]I need to code a decrease of $holder – can I do this and will create any problems-
$custom_fields[‘Places left’]= $custom_fields[‘Places left’]-1;
Thanks for any advice on this.
June 16, 2017 at 2:59 am #1299004PHILLIPA
ParticipantHi I have come up with this myself but have not run it due to safety concerns – Does this look ok and will it create any problems – since I am updating the database directly
$holdvalue=$custom_fields['Places Left'] ; $holdvalue = $holdvalue -1; $args = array( 'Places Left' => $holdvalue ); tribe_update_event($event_id, $args);June 16, 2017 at 2:22 pm #1299384Barry
MemberHi Phillipa,
It’s hard to say without knowing more about your customization work, as there are two different types of custom field – those supported natively by WordPress and a richer implementation provided by Events Calendar PRO.
Looking at your code my assumption is you are using regular WordPress custom fields and so I’d recommend you perform the update using the update_post_meta() function, something like this:
update_post_meta( $event_id, 'Places Left', $holdvalue );
Remember! If you have concerns over the safety of code then slow down, make a backup and/or practice on a test or staging site first!
June 17, 2017 at 3:14 am #1299556PHILLIPA
ParticipantThank you for your reply Barry, in fact I added it as a tribe custom field. So would this be the right function:
tribe_update_event($event_id, $args);June 19, 2017 at 6:03 am #1299928Barry
MemberThanks for clarifying 🙂
To work with Events Calendar PRO’s custom fields you’ll probably find it easiest to define a helper function like this one:
https://gist.github.com/barryhughes/2e38cf6cd978255e87b5e74b6c6d4530
You can then use it in this sort of style:
// Update the "Event Facilities" custom field update_ecp_custom_field( 123, 'Event Facilities', 'childcare, washrooms, limited groceries' );
Does that help?
July 11, 2017 at 9:37 am #1319563Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Update single event meta data’ is closed to new replies.
