Working, thanks!
It’s a date-time field.
The datahora_prova has this format: d/m/Y | H:i. Can be this the problem?
Thanks for the help.
It returns this:
Array
(
[posts_per_page] => 7
[post_type] => competicions
[orderby] => meta_value
[order] => asc
[meta_key] => datahora_prova
[meta_query] => Array
(
[0] => Array
(
[key] => datahora_prova
[value] => 20220706
[compare] => >=
)
[1] => Array
(
[key] => datahora_prova
[value] => 20220731
[compare] => <=
)
)
)
The code I posted before (your code + the rest of “mine”) I understand that it’s correct, right?
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; ?>
Thanks for the reply. From what I’ve managed to find out, php doesn’t work with the plugin’s format, which is Timber (twig files). That’s why the ACF php code doesn’t work, although the shortcodes don’t work either…
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.