I want to create a code snippet for expiration of post after x days from the post published date, I tried with this code but I always displays the true condition, what am I doing wrong?

$pfx_date       = get_the_date('d/m/Y');
$datacorrente   = date('d/m/Y', strtotime("-5 days"));

if ( $pfx_date <= $datacorrente ) { 
    echo 'post expired'; 
} else { 
    echo 'post open'; 
}

“-5 days” is the x days variable after the post is expired.

2 Answers
2

You’re comparing strings. For dates this will only ever work out if you use a yyyymmdd format or similar.

Leave a Reply

Your email address will not be published. Required fields are marked *