Home › Forums › Calendar Products › Community Events › Set custom event meta
- This topic has 3 replies, 2 voices, and was last updated 11 years, 6 months ago by
Barry.
-
AuthorPosts
-
October 15, 2014 at 8:49 am #812367
louisecote
ParticipantHello.
I’ve added two custom meta fields (‘_EventCreationDate’,’_EventAdPeriod’,) to The Events Calendar Class (the-events-calendar.class.php).
I want to set these fields, when user clicks Submit button on Community Events page (/events/community/add).
I guess I need to edit Submission_Handler.php, maybe save() function.
I tried using this line of code, but it doesn’t work.
TribeEventsAPI::saveEventMeta( $this->event_id, array(“_EventCreationDate”=>”2014″,”_EventAdPeriod”=>”12”));October 15, 2014 at 2:38 pm #813014Barry
MemberHi louisecote,
Customizations are really something we need to leave in your hands, but I’d be happy to point you in the right direction if I can 🙂
I’ve added two custom meta fields (‘_EventCreationDate’,’_EventAdPeriod’,) to The Events Calendar Class (the-events-calendar.class.php).
Modifying core plugin code is rarely a good idea and not something we’d generally recommend. Perhaps you could implement your modifications without doing this?
I want to set these fields, when user clicks Submit button on Community Events page (/events/community/add).
WordPress itself has some useful hooks you can use such as save_post_{post_type} so you could consider listening out for the appropriate action firing and add your logic to a plugin of its own (or possibly to your theme’s functions.php file).
Since you probably only want to add these fields to events submitted via Community Events you could additionally test against the ecp_event_submission nonce which is used to protect that form, ie:
add_action( 'init', 'setup_community_submissions_marker' ); function setup_community_submissions_marker() { if ( class_exists( 'TribeEvents' ) ) add_action( 'save_post_' . TribeEvents::POSTTYPE, 'mark_community_submissions' ); } function mark_community_submissions( $post_id ) { if ( ! wp_verify_nonce( @$_POST['_wpnonce'], 'ecp_event_submission' ) ) return; update_post_meta( $post_id, 'your_custom_field', 'some_value' ); }Would that work for you?
October 16, 2014 at 2:39 am #813837louisecote
ParticipantThanks, this is exactly what I was looking for!
October 16, 2014 at 6:33 am #814095Barry
MemberAwesome 🙂
I’ll go ahead and close this thread but if we can help with anything else please don’t hesitate to open a new one and let us know – one of the team will be only too happy to help.
Last but not least, if you have a moment to spare we’d love to hear your thoughts on The Events Calendar so far over on our plugin review page – thanks again!
-
AuthorPosts
- The topic ‘Set custom event meta’ is closed to new replies.
