admin管理员组文章数量:1122846
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 } ?>
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 } ?>
Share
Improve this question
asked Nov 7, 2017 at 22:54
Alex DahlmanAlex Dahlman
54 bronze badges
1 Answer
Reset to default 0You 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 ); ?>
本文标签: The Events Calendar EventURL not displaying
版权声明:本文标题:The Events Calendar EventURL not displaying 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294404a1929350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论