0

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.

1

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);
  • I really like the suggestion and was really hoping it would work, but it is a no-go. With ACF 4.3.7, I cannot simply have multiple dates with the same Key Name. It will only store the last date over all of them, so it ends up being a single value per Key. – test May 7 '14 at 19:48
  • Are there any other Custom Fields pluggins that do do this? – test May 7 '14 at 19:49
  • This is going to be wildly complicated with SQL-- pretty sure. And this is also why I rarely plugins for things like this-- even good code usually doesn't really fit quite right. – s_ha_dum May 7 '14 at 19:52
  • I'm completely open to a pluggin-less solution. Let me know any details and I'll see what I can do. – test May 7 '14 at 19:57
  • I'm Still Looking for a Working Solution... – test May 8 '14 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.