admin管理员组文章数量:1130349
i am displaying posts selected by an ACF relationship (with object format) on a page, including custom posts like tribe_events. I want to display the date and time on the tribe_events posts, but not on the other posts. I am using this code below. It displays correctly the start date and time of the tribe_events, but it also displays the current date and time on the other posts. What can i don to have the date and time only on the tribe_events posts ? Thanks ;-)
<?php
global $post;
$posts = get_field( 'relationship' );
if( $posts ):
foreach( $posts as $p ):
setup_postdata( $p );
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
endforeach;
endif;
?>
i am displaying posts selected by an ACF relationship (with object format) on a page, including custom posts like tribe_events. I want to display the date and time on the tribe_events posts, but not on the other posts. I am using this code below. It displays correctly the start date and time of the tribe_events, but it also displays the current date and time on the other posts. What can i don to have the date and time only on the tribe_events posts ? Thanks ;-)
<?php
global $post;
$posts = get_field( 'relationship' );
if( $posts ):
foreach( $posts as $p ):
setup_postdata( $p );
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
endforeach;
endif;
?>
Share
Improve this question
edited Nov 20, 2018 at 14:12
studiok7
asked Nov 20, 2018 at 14:01
studiok7studiok7
236 bronze badges
1 Answer
Reset to default 1There are various ways to solve this. First coming to mind are checking via is_singular() or get_post_type(). Using the latter you could write
foreach( $posts as $p ):
setup_postdata( $p );
$post_type = get_post_type($p);
if ($post_type === Tribe__Events__Main::POSTTYPE) {
//or: if ($post_type === 'tribe_events') {
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
}
endforeach;
i am displaying posts selected by an ACF relationship (with object format) on a page, including custom posts like tribe_events. I want to display the date and time on the tribe_events posts, but not on the other posts. I am using this code below. It displays correctly the start date and time of the tribe_events, but it also displays the current date and time on the other posts. What can i don to have the date and time only on the tribe_events posts ? Thanks ;-)
<?php
global $post;
$posts = get_field( 'relationship' );
if( $posts ):
foreach( $posts as $p ):
setup_postdata( $p );
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
endforeach;
endif;
?>
i am displaying posts selected by an ACF relationship (with object format) on a page, including custom posts like tribe_events. I want to display the date and time on the tribe_events posts, but not on the other posts. I am using this code below. It displays correctly the start date and time of the tribe_events, but it also displays the current date and time on the other posts. What can i don to have the date and time only on the tribe_events posts ? Thanks ;-)
<?php
global $post;
$posts = get_field( 'relationship' );
if( $posts ):
foreach( $posts as $p ):
setup_postdata( $p );
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
endforeach;
endif;
?>
Share
Improve this question
edited Nov 20, 2018 at 14:12
studiok7
asked Nov 20, 2018 at 14:01
studiok7studiok7
236 bronze badges
1 Answer
Reset to default 1There are various ways to solve this. First coming to mind are checking via is_singular() or get_post_type(). Using the latter you could write
foreach( $posts as $p ):
setup_postdata( $p );
$post_type = get_post_type($p);
if ($post_type === Tribe__Events__Main::POSTTYPE) {
//or: if ($post_type === 'tribe_events') {
// Display the date of the event
$p_event = tribe_get_start_time ( $p->ID, 'j F à H \h i' );
if ( $p_event ) {
echo $p_event;
}
else '';
}
endforeach;
本文标签: tribegetstarttime displays the current date and time on other post types than tribeevents
版权声明:本文标题:tribe_get_start_time displays the current date and time on other post types than tribe_events 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749166168a2326217.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论