Order events by event date

Question

I want to alter the way an events widget works in a premium theme.

The widget works this way: it displays 3 “latest events”. Apart from the fact that I generally use it to display upcoming events, the widget doesn’t work the way I want.

This is the code involved:

<div class="widget-inner">
        <?php
            $args = array(
            'post_type' => 'event',
            'post_per_page' => $number,
            'showposts' => $number
        );
            $latest_events = new WP_Query($args);
            if ($latest_events->have_posts()):
                global $post;
        ?>
        <?php while($latest_events->have_posts()): $latest_events->the_post();

                $event_month = get_post_meta($post->ID, 'core_event_month', true);
                $event_day = get_post_meta($post->ID, 'core_event_day', true);
                $event_time = get_post_meta($post->ID, 'core_event_time', true);
                $event_location = get_post_meta($post->ID, 'core_event_location', true); 
        ?>

This thing has a terrific impact on the order of the events because in the end it displays the last PUBLISHED events, NOT the latest/upcoming events based on their dates.

So, I’m here to ask if is it possible to alter the $args passed to WP_Query to display the posts using the metas core_events_year, core_events_month and core_events_day and completely ignore the publishing date.

Can you help me?

0
, Guest 4 years 2019-11-03T04:23:14-05:00 0 Answers 68 views 0

Leave an answer

Browse
Browse