Last active
February 21, 2022 11:19
-
-
Save cliffordp/9c88e97e5f2392b1c36eabb248a50b11 to your computer and use it in GitHub Desktop.
The Events Calendar - Community Events: Enqueue Advanced Custom Fields into the Community Events add/edit form pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Unsure. I'm available for custom coding but am not currently using this to know. Good luck.
Thank you! This code that you shared us only updates the event, but it doesn't create a new one.
Solution is adding an extra step before open The Events Calendar Community Edit Event.
I just created a new template in the theme, and I added it to a Page with this template. This solution works with your solution so is complementary to create an event and edit it with your solution.
<?php
/*
Template Name: Create Event
*/
?>
<?php
acf_form_head();
get_header();
?>
<div id="content">
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => false,
'field_groups' => array('group_61e7982209f5b'),
'new_post' => array(
'post_type' => 'tribe_events',
'post_status' => 'publish'
),
'return' => '/events/community/edit/event/%post_id%',
'submit_value' => 'Create new event'
));
?>
</div>
<?php get_footer(); ?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
Thanks for this script.
I was using but now only works with Update and not on create.
Any Idea to help us?
Thanks :D