Support

Account

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)

  • I’m late to the party on this one, but with The Events Calendar changing their codebase so often, this may be useful to anyone trying to do this in 2023:

    In edit-event.php, you need to call the ACF form head:

    
    add_action( 'get_header', 'call_acf_form_head', 1 );
    function call_acf_form_head() {
       acf_form_head();
    }
    

    In the same file, you can add your field groups anywhere within the form tags:

    
    <?php
        $settings = array(
          'field_groups' => array('group_649542db656b2'),
          'form' => false
        );
        acf_form($settings);
    ?>
    

    Then in your functions.php you need to add two functions. One that fires when the event is created, and one that fires when the event is updated.

    
    add_action('tribe_community_event_created', 'events_custom_field_create', 10, 1);
    function events_custom_field_create($event_id){
    
        acf_save_post( $event_id );
    }
    
    
    add_action('tribe_community_event_updated', 'events_custom_field_update', 10, 1);
    function events_custom_field_update($event_id){
    
        acf_save_post( $event_id );
    }
    

    Note: I did try combining this into one function, but for me it didn’t work.

    Bonus bits:
    Need to add a featured image? In your image field settings, set the Field Name as _thumbnail_id.

    Want to use an image gallery, but also want to set a featured image without needing a separate field? You can save the first image uploaded to the gallery as the featured image for the event with this function:

    
    add_filter('acf/save_post', 'gallery_to_thumbnail');
    function gallery_to_thumbnail($event_id) {
    	$gallery = get_field('event_gallery', $event_id, false);
    	if (!empty($gallery)) {
    		$image_id = $gallery[0];
    		set_post_thumbnail($event_id, $image_id);
    	}
    }
    

    Make sure to replace the get_field with your Field Name.

    I hope this helps someone!