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;