Support

Account

Home Forums General Issues My date is considered old even though it is future

Solving

My date is considered old even though it is future

  • I made an event system with a custom-post. I use ACF classic.

    I therefore display my posts only if they are equal to today’s date or in the future. All old posts are therefore hidden. This all works very well.

    Problem is that when the year is 2024, everything beyond December 31, 2023 is considered old… I know this because when I change my value from ($date_event >= $today) to ($date_event <= $today) it displays it to me in my old posts..

    I don’t understand..

    <?php 
                    $loop = new WP_Query( array( 'post_type' => 'evenement', 'posts_per_page' => 10, 'meta_key' => 'start_event', 'orderby' => 'meta_value', 'order' => 'ASC' ) );
            while ( $loop->have_posts() ) : $loop->the_post();
    
                    $today = date("m-d-Y");
                    $date_event = get_field('start_event');
                ?>
                    
                <?php if ($date_event >= $today) { ?>
                    <?php
                        $date = DateTime::createFromFormat( 'm-d-Y', $date_event );
                        $date_format = $date->format( 'j F Y' );
                        $date_rendu = date_i18n("j F Y", strtotime($date_format));
                    ?>
    
              <a href="<?php echo get_permalink() ?>">
    
                <div class="image">
                  <?php echo the_post_thumbnail(); ?>
                </div>
                <div class="description">
                  <div class="dates">
                                    <?php echo $date_rendu ?>
                  </div>
                  <div class="nom">
                    <?php echo the_title(); ?>
                  </div>
                </div>
              </a>
    
                        <?php }; ?>
      
          <?php endwhile; ?>
  • What is the return format of your date field?

    Does it match the format you are using for $today?

    
    $today = date("m-d-Y");
    $date_event = get_field('start_event');
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.