// Shortcode [king_events]
function king_events ( $atts, $content = null) {
$today = date('Ymd');
$atts = shortcode_atts(
array(
'type' => '',
'number' => '-1',
),
$atts,
'king_events'
);
$args = array(
'post_type' => 'tkc-event',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'event_date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>',
'value' => $today,
'type' => 'DATE'
)
),
);
if( !empty( $atts['type'] ) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'event_type',
'field' => 'slug',
'terms' => $atts['type'],
)
);
}
$events_query = new WP_Query($args);
ob_start();
if($events_query->have_posts()) { ?>
<div class="events-wrap">
<?php
while ($events_query->have_posts()) {
$events_query->the_post(); ?>
<div class="belove-event-inner">
<div class="belove-event-img">
<a href="<?php echo get_the_post_thumbnail_url(get_the_ID(),'full'); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('big-square'); } ?>
</a>
</div>
<div class="belove-event-content">
<h3><?php echo the_title(); ?></h3>
<div class="event-details">
<?php echo the_content(); ?>
</div>
<?php if (get_field('event_link')) { ?>
<div class="belove-event-link">
<?php if(get_field('button_label')) { ?>
<a href="<?php echo get_field('event_link'); ?>" target="_blank"><?php echo get_field('button_label'); ?></a>
<?php }else { ?>
<a href="<?php echo get_field('event_link'); ?>" target="_blank">Registration</a>
<?php }?>
</div>
<?php } ?>
</div>
</div>
<?php }
wp_reset_postdata();
?>
</div>
<?php
} else { ?>
<div>No Events found</div>
<?php }
return ob_get_clean();
}
add_shortcode('king_events', 'king_events');