Support

Account

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