0

I am trying to Add the Condition if Expire date is smaller than the current date expired in the post. But the condition not working please check the code below.

    <?php if (!empty($apply_from)) { ?>
                    <li>
                        <?php 
                    $expire = get_field('expire_date');
                    $date = date('Ymd');
                            if($expire < $date) { 
                    ?>
                            <p>Expired</p>
    
                        <?php
                        } else { 
echo $expire_date; 
                        }   
                            ?>
                    
                    </li>
                    <?php 
                                
                            }
                            ?>
5
  • What does "is not working" mean? What are the exact values of $expire and $date?
    – kero
    Commented Jan 17, 2022 at 12:35
  • The $date is the Current, and $expire date I will set during post publish which will be bigger than the $date. When $expire date is over it will be smaller than $current shown above the message. for instance $date = current date 17-1-2022 $expire = I set 18-1-2022 Means not Expire $date = current date 17-1-2022 $expire = I set 16-1-2022 Means Expire
    – stepiadm
    Commented Jan 17, 2022 at 12:49
  • (I meant check the real values of these variables, it might be that $expire comes in the format Y-m-d not Ymd e.g.)
    – kero
    Commented Jan 17, 2022 at 12:55
  • Can you check the link values are correct placements.iadm.edu.pk here $date is current date
    – stepiadm
    Commented Jan 17, 2022 at 13:37
  • The current date is 17-1-2022 and the expired date in 2 posts is 2021 but does not show expire value in the post. Remember these all posts are old when I edit any post-working very well for instance first post I edit and change the value then it works well.
    – stepiadm
    Commented Jan 17, 2022 at 14:03

0

Your Answer

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

Browse other questions tagged or ask your own question.