Using Tribe_Get_Events is causing featured images in main calendar to break?

Home Forums Calendar Products Events Calendar PRO Using Tribe_Get_Events is causing featured images in main calendar to break?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1351872
    tradingbo
    Participant

    Hi ECP,

    Using the following code to create a ‘billboard’ like upcoming event list on our homepage. The code is sourced as per your
    https://theeventscalendar.com/knowledgebase/using-tribe_get_events/ link.

    <?php
    // Ensure the global $post variable is in scope
    global $post;
     
    // Retrieve the next 5 upcoming events
    $events = tribe_get_events( array(
    	'post_status'=>'publish',
    	'eventDisplay'   => 'list',
        'posts_per_page' => 6
    
    ) );
     
    // Loop through the events: set up each one as
    // the current post then use template tags to
    // display the title and content
    foreach ( $events as $post ) {
        setup_postdata( $post );
     
        // This time, let's throw in an event-specific
        // template tag to show the date after the title!
            
            echo " <a href='$post->guid'><li><span>$post->post_title </span></a>";
            echo tribe_get_start_date( $post->ID, false, 'j<\s\u\p>S<\/\s\u\p> F Y', "</li>" );
            }   ?>

    This is working great, however seems to have messed with the event images in the single-event-photo-view? Event images are displaying correctly on the overall photo view grid layout, however when you choose an event and view it individually they all display a featured image from the same random event?

    Is it not ok to use an event loop in multiple places on a site?

    Many Thanks,
    M

    #1351896
    tradingbo
    Participant

    Apologies managed to resolve issue by reverting to $events as $event in the loop.
    Amended code to…

    			<?php
    // Ensure the global $post variable is in scope
    global $post;
     
    // Retrieve the next 5 upcoming events
    $events = tribe_get_events( array(
    	'post_status'=>'publish',
    	'eventDisplay'   => 'list',
        'posts_per_page' => 6
    
    ) );
     
    // Loop through the events: set up each one as
    // the current post then use template tags to
    // display the title and content
    foreach ( $events as $event ) {
        setup_postdata( $event );
     
        // This time, let's throw in an event-specific
        // template tag to show the date after the title!
            
            echo '<li><a><span>'.get_the_title( $event->ID ).'</span></a>';
            echo tribe_get_start_date( $event->ID, false, 'j<\s\u\p>S<\/\s\u\p> F Y', "</li>" );
    
            } 
            
            ?>

    Thanks

    #1351899
    tradingbo
    Participant

    Also removed <span> as this is now redundant

    #1352343
    Jennifer
    Keymaster

    Hi Michael,

    I’m glad to hear you were able to get this resolved, and thanks for posting your solution here for others to see as well!

    I’ll go ahead and close out this thread, but please feel free to open a new one if you have any further questions.

    Thanks,

    Jennifer

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Using Tribe_Get_Events is causing featured images in main calendar to break?’ is closed to new replies.