Support

Account

Home Forums Front-end Issues Post Object Field in Events Calendar Meta Details Section

Solving

Post Object Field in Events Calendar Meta Details Section

  • Hello,

    To be as succinct as possible, I am attempting to create a relationship post object field so that, on the backend, I may select from The Events Calendar Pro’s native “Organizers” post type and output a new event details meta section on the frontend.

    (Basically, I want a “Speakers” section and an “Organizers” section, but because individuals may have either role depending on the event, I do not want to create a new custom post type and have to duplicate much of the same content for those who both speak and organize at a given event)

    Of course, implementing the new section was easy on the backend. I am able to select from the same bank of “Speakers/Organizers” on the backend and it saves that data no problem. I am running into issues on the front-end, however.

    All it is outputting on the frontend is “Array”

    Here is the coded template file (/modules/meta/theorganizers.php) I am failing with:

    <?php
    
    $field_name = "the_organizers";
    $field = get_field_object($field_name);
    
    ?>
    
    <div class="tribe-events-meta-group tribe-events-meta-group-organizer">
    	<h3 class="tribe-events-single-section-title"><?php echo "Organizers"; ?></h3>
    	<dl>
    		<?php
    		do_action( 'tribe_events_single_meta_organizer_section_start' );
    		
    		
    		echo $field;
    	
    	
    	do_action( 'tribe_events_single_meta_organizer_section_end' );
    		?>
    	</dl>
    </div>

    For what it’s worth, here is the plugin’s native template file for organizers, found at found at /modules/meta/organizer.php (I’m sorry if the terminology is getting confusing. On the frontend, I changed the header to the all encompassing Speakers | Organizers):

    <?php
    /**
     * Single Event Meta (Organizer) Template
     *
     * Override this template in your own theme by creating a file at:
     * [your-theme]/tribe-events/modules/meta/organizer.php
     *
     * @package TribeEventsCalendar
     * @version 4.4
     */
    
    $organizer_ids = tribe_get_organizer_ids();
    $multiple = count( $organizer_ids ) > 1;
    
    $phone = tribe_get_organizer_phone();
    $email = tribe_get_organizer_email();
    $website = tribe_get_organizer_website_link();
    ?>
    
    <div class="tribe-events-meta-group tribe-events-meta-group-organizer">
    	<h3 class="tribe-events-single-section-title"><?php echo tribe_get_organizer_label( ! $multiple ); ?></h3>
    	<dl>
    		<?php
    		do_action( 'tribe_events_single_meta_organizer_section_start' );
    
    		foreach ( $organizer_ids as $organizer ) {
    			if ( ! $organizer ) {
    				continue;
    			}
    
    			?>
    			<dt style="display:none;"><?php // This element is just to make sure we have a valid HTML ?></dt>
    			<dd class="tribe-organizer">
    				<?php echo tribe_get_organizer_link( $organizer ) ?>
    			</dd>
    			<?php
    		}
    
    		if ( ! $multiple ) { // only show organizer details if there is one
    			if ( ! empty( $phone ) ) {
    				?>
    				<dt>
    					<?php esc_html_e( 'Phone:', 'the-events-calendar' ) ?>
    				</dt>
    				<dd class="tribe-organizer-tel">
    					<?php echo esc_html( $phone ); ?>
    				</dd>
    				<?php
    			}//end if
    
    			if ( ! empty( $email ) ) {
    				?>
    				<dt>
    					<?php esc_html_e( 'Email:', 'the-events-calendar' ) ?>
    				</dt>
    				<dd class="tribe-organizer-email">
    					<?php echo esc_html( $email ); ?>
    				</dd>
    				<?php
    			}//end if
    
    			if ( ! empty( $website ) ) {
    				?>
    				<dt>
    					<?php esc_html_e( 'Website:', 'the-events-calendar' ) ?>
    				</dt>
    				<dd class="tribe-organizer-url">
    					<?php echo $website; ?>
    				</dd>
    				<?php
    			}//end if
    		}//end if
    
    		do_action( 'tribe_events_single_meta_organizer_section_end' );
    		?>
    	</dl>
    </div>
    

    The template files are then called in The Events Calendar’s meta.php (/modules/meta.php):

    <?php
    /**
     * Single Event Meta Template
     *
     * Override this template in your own theme by creating a file at:
     * [your-theme]/tribe-events/modules/meta.php
     *
     * @package TribeEventsCalendar
     */
    
    do_action( 'tribe_events_single_meta_before' );
    
    // Check for skeleton mode (no outer wrappers per section)
    $not_skeleton = ! apply_filters( 'tribe_events_single_event_the_meta_skeleton', false, get_the_ID() );
    
    // Do we want to group venue meta separately?
    $set_venue_apart = apply_filters( 'tribe_events_single_event_the_meta_group_venue', false, get_the_ID() );
    ?>
    
    <?php if ( $not_skeleton ) : ?>
    	<div class="tribe-events-single-section tribe-events-event-meta primary tribe-clearfix">
    <?php endif; ?>
    
    <?php
    do_action( 'tribe_events_single_event_meta_primary_section_start' );
    
    // Always include the main event details in this first section
    tribe_get_template_part( 'modules/meta/details' );
    tribe_get_template_part( 'modules/meta/theorganizers' );
    
    // If we have no map to embed and no need to keep the venue separate...
    if ( ! $set_venue_apart && ! tribe_embed_google_map() ) {
    	tribe_get_template_part( 'modules/meta/venue' );
    } elseif ( ! $set_venue_apart && ! tribe_has_organizer() && tribe_embed_google_map() ) {
    	// If we have no organizer, no need to separate the venue but we have a map to embed...
    	tribe_get_template_part( 'modules/meta/venue' );
    	echo '<div class="tribe-events-meta-group tribe-events-meta-group-gmap">';
    	tribe_get_template_part( 'modules/meta/map' );
    	echo '</div>';
    } else {
    	// If the venue meta has not already been displayed then it will be printed separately by default
    	$set_venue_apart = true;
    }
    
    // Include organizer meta if appropriate
    if ( tribe_has_organizer() ) {
    	tribe_get_template_part( 'modules/meta/organizer' );
    }
    
    do_action( 'tribe_events_single_event_meta_primary_section_end' );
    ?>
    
    <?php if ( $not_skeleton ) : ?>
    	</div>
    <?php endif; ?>
    
    <?php if ( $set_venue_apart ) : ?>
    	<?php if ( $not_skeleton ) : ?>
    		<div class="tribe-events-single-section tribe-events-event-meta secondary tribe-clearfix">
    	<?php endif; ?>
    	<?php
    	do_action( 'tribe_events_single_event_meta_secondary_section_start' );
    
    	tribe_get_template_part( 'modules/meta/venue' );
    	tribe_get_template_part( 'modules/meta/map' );
    
    	do_action( 'tribe_events_single_event_meta_secondary_section_end' );
    	?>
    	<?php
    	if ( $not_skeleton ) : ?>
    		</div>
    	<?php endif; ?>
    <?php
    endif;
    do_action( 'tribe_events_single_meta_after' );
    
  • Including a screenshot of the frontend

  • Got it! If this is of any use to anyone else, here is the working template:

    <?php
    /**
     * Single Event Meta (Organizer) Template
     *
     * Override this template in your own theme by creating a file at:
     * [your-theme]/tribe-events/modules/meta/organizer.php
     *
     * @package TribeEventsCalendar
     * @version 4.4
     */
    
    ?>
    
    <div class="tribe-events-meta-group tribe-events-meta-group-organizer">
    	<h3 class="tribe-events-single-section-title"><?php echo "Organizers"; ?></h3>
    	<dl>
    		
    	<?php	$posts = get_field('the_organizers');?>
    	
    	<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    	    <dt style="display:none;"><?php // This element is just to make sure we have a valid HTML ?></dt>
    			<dd class="tribe-organizer">
    	    	<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
    	    	<?php the_field('author', $p->ID); ?>
    	    </dd>
    	<?php endforeach; ?>
    	
    	<?php do_action( 'tribe_events_single_meta_organizer_section_end' ); 
    		?>
    	</dl>
    </div>
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Post Object Field in Events Calendar Meta Details Section’ is closed to new replies.