Event时间离自己最近时间查询排序

Published
May 11, 2022
浏览次数 :  3

<?php
            $today = date('Ymd');
            $homepageEvents = new WP_Query(array(
                'posts_per_page' => -1,
                'post_type' => 'events',
                'orderby' => 'meta_value_num',
                'order' => 'ASC',
                'meta_query' => array(array(
                    'key' => 'event_date',
                    'compare' => '>=',
                    'value' => $today,
                    'type' => 'numeric'
                ))
            ));

            while ($homepageEvents->have_posts()) {
                $homepageEvents->the_post(); ?>

                <div class="event-summary">
                    <a class="event-summary__date t-center" href="#">
                        <span class="event-summary__month">
                            <?php 
                        $eventDate = new DateTime(get_field('event_date'));
                        echo $eventDate->format('M');
                         ?>
                             
                         </span>
                        <span class="event-summary__day"><?php echo $eventDate->format('d'); ?></span>
                    </a>
                    <div class="event-summary__content">
                        <h5 class="event-summary__title headline headline--tiny"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
                        <p><?php if (has_excerpt()) {
                                echo get_the_excerpt();
                            } else {
                                echo wp_trim_words(get_the_content(), 18);
                            } ?><a href="<?php the_permalink(); ?>" class="nu gray">Learn more</a></p>
                    </div>
                </div>



            <?php

            }


            ?>

Top