List of Events with Multiple Dates: Only NEXT Date

I have Advanced Custom Fields 4.3.7 by Elliot Condon and Custom Post Type UI version: 0.8.2 by WebDevStudios.com "plugged" in and would like to limit pluggins to only those two.

I have multiple ACF's for date_one, date_two, date_three,... up to 20 (unlikely any event gets past 10, but just in case) and are in Y-m-d PHP format.

Goal: All event lists will be chronologically ordered by their NEXT event date and will only be a single line of information with only one date (the NEXT event date).

I started with the below to get only today's events but can't even seem to get that to work and it doesn't address the issue of tomorrow's events.

            ?php query_posts(array(
                'meta_query'    = array(
                    'relation' = 'OR',
                    array(
                       'key'        = 'date_one',
                       'value'      = date( 'Y-m-d' ),
                       'compare'    = '=',
                       'type'       = 'DATE'
                        ),
                    array(
                       'key'        = 'date_two',
                       'value'      = date( 'Y-m-d' ),
                       'compare'    = '=',
                       'type'       = 'DATE'
                        ),
                    array(
                        ...
                        ),
                    ),
                'posts_per_page'  = 30,
                'post_type'     = 'performances'
            ) ); ?

Ultimately, I have a fallback idea that involves only start and end dates, but I am really hoping for this particular feature.

Topic lists php events query customization Wordpress

Category Web


I think that you have poor data design. The solution, in my opinion, is to alter how your data is saved. If you saved all of your dates under the same key name you could run a relatively simple query to get the next date.

$args = array(
'meta_query'    => array(
    'relation' => 'OR',
    array(
    'key'        => 'event_dates',
    'value'      => date("Y-m-d H:i:s",strtotime('today midnight')), // set
    'compare'    => '>',
    'type'       => 'DATE'
    ),
    ),
'posts_per_page'  => 30,
'post_type'     => 'performances'
);
$loop = new WP_Query( $args );
var_dump($loop->request);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.