I have some code below that displays one event on my wordpress homepage from the Tribe Event Calendar.
I'm trying to figure out that if there is no events to display, then I want to setup an alert.
<?php
add_filter('tribe_events_pre_get_posts', 'filter_tribe_featured_event', 100);
function filter_tribe_featured_event ($wp_query) {
if ( !is_admin() ) {
$new_meta = array();
$today = new DateTime();
// Join with existing meta_query
if(is_array($wp_query->meta_query))
$new_meta = $wp_query->meta_query;
// Add new meta_query, select events ending from now forward
$new_meta[] = array(
'key' => '_EventStartDate',
'type' => 'DATETIME',
'compare' => '>=',
'value' => $today->format('Y-m-d H:i:s')
);
$wp_query->set( 'meta_query', $new_meta );
}
return $wp_query;
}
global $post;
$all_events = tribe_get_events(array(
'eventDisplay'=>'all',
'posts_per_page'=>1,
'orderby'=>'post_date',
'order'=>'ASC',
));
foreach($all_events as $post) {
(setup_postdata($post)) ;
?>
<div class="row">
<div class="col-xs-7"> <a href="<?php the_permalink(); ?>">
<img src="<?php the_field('home_page_image'); ?>" class="img-responsive img-thumbnail" />
</a> </div>
<div class="col-xs-5">
<h1><?php the_title(); ?></h1>
<h2><?php echo tribe_get_start_date(null, false, 'F jS Y'); ?> at <?php echo tribe_get_start_time(); ?></h2>
<h3><?php echo tribe_get_formatted_cost(); ?></h3>
<h4><?php echo tribe_get_venue(); ?></h4>
<?php the_excerpt() ?>
</div>
<?php } //endforeach ?>
<?php wp_reset_query(); ?>
</div>
Aucun commentaire:
Enregistrer un commentaire