0

I have a custom footer with events being brought in. However, links are no longer showing while using tribe_get_event_meta. The link given is just my home url link and not the link to the event page. My link code is

<?php
global $post;
$i = 0;
$events = tribe_get_events( array(
 'posts_per_page' => 3,
  ));

  foreach ( $events as $post ) {
  setup_postdata( $post );
?>

  <a class="event-links" href="<?php echo tribe_get_event_meta( get_the_ID(), '_EventURL', true ); ?>" target="_self">
  <li class="evlist" id = "evli-<?php echo $i;?>" >
  <span class="evdate" id = "evspd-<?php echo $i;?>" >
  <?php echo tribe_get_start_date($post, false, 'F j' );?>
  </span >
  <span class="evspan" id="evspanid-<?php echo $i;?>"><h2 class="evhead" id = "evspt-<?php echo $i;?>" >
  <?php echo "$post->post_title"; ?>:</h2 >
  <?php echo  tribe_events_get_the_excerpt( $post );?>
  </span >
</li >
</a>
<?php $i++; ?>
<?php } ?>
0

You problem likely results from the tribe_events_get_the_excerpt() function calling wp_reset_postdata(), which resets the global $post object back to the original query (i.e., the page the footer is on). get_the_ID() returns the ID of the global $post object, so you will get the page’s ID instead of the event’s from within the loop. And setup_postdata() does not assign the global $post variable.

Simpliest solution in this case should be to replace get_the_ID() with $post->ID ($post referring to the loop’s local event value here, not the global):

<?php echo tribe_get_event_meta( $post->ID, '_EventURL', true ); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.