$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>tribe_get_start_time displays the current date and time on other post types than tribe_events|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

tribe_get_start_time displays the current date and time on other post types than tribe_events

matteradmin6PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

There 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;
Post a comment

comment list (0)

  1. No comments so far