Home › Forums › General Issues › Filter Custom Post Type by ACF Date Picker Field › Reply To: Filter Custom Post Type by ACF Date Picker Field
Hi @codeview
Thanks for the follow up.
You will need to debug your code line by line to find out why the date is incorrect. You can debug like this:
<?php
/*
* Create PHP DateTime object from Date Piker Value
* The ACF "Workaround" for PHP 5.2 as shown in the docs
*/
$date = get_field('event_enddate'); // $date = 19881123 (23/11/1988)
echo '<pre>';
print_r( $date );
echo '</pre>';
die;
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
echo '<pre>';
print_r( $y );
echo '</pre>';
echo '<pre>';
print_r( $m );
echo '</pre>';
echo '<pre>';
print_r( $d );
echo '</pre>';
die;
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
echo '<pre>';
print_r( $time );
echo '</pre>';
die;
?>
Please note there are 3 sections to this code which print out and die. Once you are happy with the result, just remove that print_r section and allow the next to run.
This should help explain where the issue starts
Thanks
E
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.