Search code examples
phpwordpressadvanced-custom-fieldsacfpro

ACF DateTime/Date Picker : get posts greater than the current date


here the case :

Date field

$start_date = get_sub_field('start_date');
$date = DateTime::createFromFormat('F j, Y', $start_date);
$sdate = $date->format('F j, Y');

Current Date in wordpress

$current_date = date('F j, Y');

I want to make one condition that it shows only fields greater than the current date.

so when I am doing this

 if ($sdate > $current_date) { }

The results are not as expected as it displays the values of older month also. What I am doing wrong ?Any Help?


Solution

  • Use the following code. It can help you

    if (strtotime($sdate) > strtotime($current_date)) { }