Support

Home Forums Community Forum Related Events ACF with featured image

Related Events ACF with featured image

Posted: June 15, 2016 at 5:24 pm

Viewing 1 reply thread


visualcreature

June 15, 2016 at 5:24 pm

I’ve followed this guide (https://eventespresso.com/wiki/adding-related-events-using-advanced-custom-fields/) to get an event to display related event. Works perfectly, however I want to add the featured image of each related event as well.

So I tried to re-use the code from content-espresso_events-thumbnail.php, but it shows the featured image from the current event page. Does anyone know how I should re-write the code?

Thanks

/* Show Related Events */
function ee_related_events() {
	$posts = get_field('events');
	if( $posts && is_singular( array( 'espresso_events') ) ): ?>
		<div class="related-events">
		<h3 class="event-venues-h3 ee-event-h3">Gerelateerde events</h3>
		<ul>
			<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
            <?php
                $img_ID = get_post_thumbnail_id( $post->ID );
                $featured_img = wp_get_attachment_image_src( $img_ID, 'small' );
            ?>
				<li>
					<a href="<?php echo get_permalink( $p->ID ); ?>">
                        <div class="related-events-img" style="background:url(<?php echo $featured_img[0]; ?>)

;”></div>
<h4 class=”related-events-title”><?php echo get_the_title( $p->ID ); ?></h4>

<?php endforeach; ?>

</div>
<?php endif; ?>
<?php
}
add_action( ‘AHEE_event_details_after_the_content’, ‘ee_related_events’ );
`


visualcreature

June 15, 2016 at 5:27 pm

Oops, something went wrong using the code tag. Here’s the proper code I have so far.


/* Show Related Events */
function ee_related_events() {
	$posts = get_field('events');
	if( $posts && is_singular( array( 'espresso_events') ) ): ?>
		<div class="related-events">
		<h3 class="event-venues-h3 ee-event-h3">Gerelateerde events</h3>
		<ul>
			<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
            <?php
                $img_ID = get_post_thumbnail_id( $post->ID );
                $featured_img = wp_get_attachment_image_src( $img_ID, 'small' );
                //$caption = esc_attr( get_post( get_post( $img_ID ))->post_excerpt );
            ?>
				<li>
					<a href="<?php echo get_permalink( $p->ID ); ?>">
                        <div class="related-events-img" style="background:url(<?php echo $featured_img[0]; ?>) center center / cover;"></div>
                        <h4 class="related-events-title"><?php echo get_the_title( $p->ID ); ?></h4>
                    </a>
				</li>
			<?php endforeach; ?>
		</ul>
		</div>
	<?php endif; ?>
<?php
}
add_action( 'AHEE_event_details_after_the_content', 'ee_related_events' );
Viewing 1 reply thread

The support post ‘Related Events ACF with featured image’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso