Home › Forums › ACF PRO › ACF Date Field doesnt'work since WP 5.1.1 › Reply To: ACF Date Field doesnt'work since WP 5.1.1
Hi,
I was on my way to write a new post on the forum when I read this one. So I post here, hope this is relevant.
The code below was working like a charm, and it doesn’t since last wp update (Wp 5.1.1) with ACF 5.7.13.
Basically I call my custom post type ‘event’ twice. One time for the futur events, one time for the past event.
Since WP update, the futur event doesn’t display.
The initial code
$today = date("Ymd");
// Futur event (works before update)
$nextevents_args = array(
'post_type' => 'event',
'post_status' => 'publish',
'meta_query' => array(
array(
"key" => "date",
"value" => $today,
"compare" => ">"
)
),
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => 'date',
'order' => 'ASC',
);
$nextevents = new WP_Query( $nextevents_args );
if ($nextevents->have_posts()):
while ($nextevents->have_posts()) :
$nextevents->the_post();
the_title();
endwhile;
endif;
wp_reset_postdata();
// Past events
$oldevents_args = array(
'post_type' => 'event',
'post_status' => 'publish',
'meta_query' => array(
array(
"key" => "date",
"value" => $today,
"compare" => "<"
)
),
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => 'date',
'order' => 'DESC',
);
$oldevents = new WP_Query($oldevents_args);
if ($oldevents->have_posts() ):
while ($oldevents->have_posts() ) :
$oldevents->the_post();
the_title();
endwhile;
endif;
wp_reset_postdata();
In this example, the past events are displayed, the futur events are not.
I’ve tested
var_dump($today) // return '20190419'
Where I’m loosing my hair :
1) The two queries are exactly the same, only the “compare” argument is different.
2) In the “futur event” query, if I replace
"key" => "date",
"value" => $today,
"compare" => ">"
by
"key" => "date",
"value" => '20190419',
"compare" => ">"
It works !!
Also :
– I’ve set up a new event today (in wp 5.1.1 / acf 5.7.13), I check and the field date is saved into the DB
– I change the type of $today into ‘integrer’ but that doesn’t change anything. The futur event are still not showing.
Hope someone can help,
Thank you
PS : sorry if I’m not on the right forum post.
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.