Home › Forums › Front-end Issues › ACF Integration with Community Events Plugin (The Events Calendar) › Reply To: ACF Integration with Community Events Plugin (The Events Calendar)
Found in this thread here: https://theeventscalendar.com/support/forums/topic/where-to-place-acf_form_head-to-save-submitted-data/#dl_post-1364986
An Events Calendar Pro dev created a snippet, and though I placed it within my functions.php file, none of the data entered in the ACF fields is saved upon hitting submit on the front-end (it does save when editing via admin backend). Still, I’m hoping it potentially offers some clues:
<?php
/**
* The Events Calendar - Community Events: Enqueue Advanced Custom Fields into
* the Community Events add/edit form pages.
*
* This will get ACF loaded but you will need to add your own additional code to
* get ACF to do anything at all on the Community Events forms.
*
* @see cliff_is_community_page
*
* @link https://gist.github.com/cliffordp/9c88e97e5f2392b1c36eabb248a50b11
* @link https://www.advancedcustomfields.com/
* @link https://theeventscalendar.com/support/forums/topic/where-to-place-acf_form_head-to-save-submitted-data/
*/
add_action( 'wp_head', 'cliff_add_acf_to_ce' );
function cliff_add_acf_to_ce() {
if (
! function_exists( 'acf_form_head' )
|| ! function_exists( 'cliff_is_community_page' )
|| false === cliff_is_community_page()
) {
return;
}
acf_form_head();
}
/**
* Return TRUE if we are in the Community Events Add Event or Edit Event form.
*
* @return bool
*/
function cliff_is_community_page() {
$main = tribe( 'community.main' );
if ( empty( $main ) ) {
// Community Events is not active (or may somehow not be loaded correctly)
return false;
}
$event_post_type = Tribe__Events__Main::POSTTYPE;
$action = Tribe__Utils__Array::get( $main->context, 'action' );
$ce_post_type = Tribe__Utils__Array::get( $main->context, 'post_type', $event_post_type ); // assume event post type if not set
// bail if we are not doing what is expected from the start
if ( $event_post_type !== $ce_post_type ) {
return false;
}
if (
'edit' === $action
|| 'add' === $action
) {
return true;
} else {
// if empty( $action ), you might be in the Community Events List view
return false;
}
}
I should also note that he described the CE front-end form like this:
“The Community Events form is actually not a regular WordPress post or archive page; it’s a WP Router “page”.
tribe_events_community_form might be the action hook you’re looking for. I found it in the render() method inside /wp-content/plugins/the-events-calendar-community-events/src/Tribe/Event_Form.php
Please let me know how this goes for you.”
And:
“Since you want it in wp_head(), I think the best way is to actually use that hook.
You could reference this is_community_page() method as a check inside the code you hook into wp_head(): https://github.com/moderntribe/products-extensions/blob/master/tribe-ext-community-currency-symbol/index.php#L294-L331”
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.