Support

Account

Home Forums ACF PRO Add Relationship Field to Events Loop

Unread

Add Relationship Field to Events Loop

  • Pertaining to The Events Calendar Pro:

    I am successfully outputting my relationship meta field values on the front end of single events pages with the following code:

    
     <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>

    By default, the native Organizer custom post type of The Events Calendar outputs all events an individual organizer is part of inside of an events loop on that respective organizer’s Single Organizer Page.

    However, only if the individual is selected under the native Organizers meta section will the event be added to that organizer/speaker’s upcoming events loop.

    Is there a way to call all related instances of the ACF relationship field into the tribe_events_loop as well?

    This is my failed attempt:

    <?php
    		
    		// Use the tribe_events_single_organizer_posts_per_page to filter the number of events to get here.
    		echo tribe_organizer_upcoming_events( $organizer_id );
    		echo tribe_organizer_upcoming_events( $variable ); 
    		$variable = get_field('the_organizers', $post->ID);?>

    And here is the function that may be helpful:

    function tribe_organizer_upcoming_events( $post_id = false ) {
    
    		$post_id = Tribe__Events__Main::postIdHelper( $post_id );
    
    		if ( $post_id ) {
    
    			$args = array(
    				'organizer'      => $post_id,
    				'eventDisplay'   => 'list',
    				'posts_per_page' => apply_filters( 'tribe_events_single_organizer_posts_per_page', 100 ),
    			);
    
    			$html = tribe_include_view_list( $args );
    
    			return apply_filters( 'tribe_organizer_upcoming_events', $html );
    		}
    	}
Viewing 1 post (of 1 total)

The topic ‘Add Relationship Field to Events Loop’ is closed to new replies.