Support

Account

Home Forums General Issues Only show my posts if the date picker date is still in the future or today

Solving

Only show my posts if the date picker date is still in the future or today

  • I would like to display only events in the future or those taking place on the same day. All posts whose date picker start_event is older than today’s date should not be displayed, but I can’t do it…

          <?php $loop = new WP_Query( array( 'post_type' => 'evenement', 'posts_per_page' => 10 ) ); ?>
          <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
      
              <a href="<?php echo get_permalink() ?>">
                <div class="image">
                  <?php echo the_post_thumbnail(); ?>
                </div>
                <div class="description">
                  <div class="dates">
                      <?php echo get_field('start_event') ?> à <?php echo get_field('hour_start_event') ?>
                  </div>
                  <div class="nom">
                    <?php echo the_title(); ?>
                  </div>
                </div>
              </a>
      
          <?php endwhile; ?>
  • I tried this below but it seems it only compares the day and not the rest of the date. If the day is a smaller number than today’s day, it does not display it..

    
    <?php $loop = new WP_Query( array( 'post_type' => 'evenement', 'posts_per_page' => 10 ) ); ?>
          <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
                <?php 
                    $today = date("d/m/y");
                    $date_event = date(get_field('start_event'));
                ?>
    
                            
      
                        <?php if (get_field('start_event') >= $today) { ?>
              <a href="<?php echo get_permalink() ?>">
                <div class="image">
                  <?php echo the_post_thumbnail(); ?>
                </div>
                <div class="description">
                  <div class="dates">
                      <?php echo get_field('start_event') ?> à <?php echo get_field('hour_start_event') ?>
                  </div>
                  <div class="nom">
                    <?php echo the_title(); ?>
                  </div>
                </div>
              </a>
                        <?php }; ?>
      
          <?php endwhile; ?>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.