0

I have a custom field. I would like to change the text of that custom field after x days.

I want something like this:

if ( published post is more than 90 days old ) {
    echo "your post is more than 90 days old"; 
}
else {
    echo "your post is less than 90 days old";
}

Can anyone help me to achieve this?

Thanks.

1 Answer 1

1

You shouldn't need to use a meta field for this logic.

In the loop $post->post_date holds when the post is published. From there you can determine if the date is 90 days old:

$datetime = strtotime($post->post_date);
if( $datetime < ( time() - ( 60 * 60 * 24 * 90 ) ) ) {
    echo "> 90 days old"
} else {
    echo "< 90 days old"
}
1
  • ROFL at the MR.Brady. Inside joke.
    – Scott
    Commented Aug 10, 2011 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.