Home › Forums › General Issues › Show only upcoming events from current month › Reply To: Show only upcoming events from current month
Thank you, but the code returns me nothing. Have I miss something?
<?php
$today = date('Ymd');
$last_of_month = date('Ymt', strtotime(date('Y-m-d')));
$args = array(
'posts_per_page' => 7,
'post_type' => 'competicions',
'orderby' => 'meta_value',
'order' => 'asc',
'meta_key' => 'datahora_prova', //ACF date field
'meta_query' => array(
array(
'key' => 'datahora_prova',
'value' => $today,
'compare' => '>=',
),
array(
'key' => 'datahora_prova',
'value' => $last_of_month,
'compare' => '<=',
)
)
);
$upcoming_events = new WP_Query( $args );
if ( $upcoming_events->have_posts() ) :
?>
<?php while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post(); ?>
<div class="widget_next_competicions_title">
<?php $permalink = get_permalink(); the_title('<a href="' . $permalink . '">', '</a>'); ?>
</div>
<div class="widget_next_competicions_date">
<?php echo get_field('datahora_prova'); ?>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.