0

I have a WP_Query function that uses these arguments:

     $args = array(
             'post_type' => 'exhibit',
             'post_status' => 'publish',
             'meta_query' => array(
                 'relation' => 'AND',
                 'date_clause' => array(
                     'key' => 'exhibit_end_date',
                     'value' => strtotime('tomorrow'),
                     'compare' => '>='
                 ),
                 'location_clause' => array(
                     'key' => 'exhibit_location'
                 )
             ),
             'orderby' => 'location_clause'
         );

The idea is to display exhibits whose end date is less than tomorrow's date. The values are stored as unix timestamps. For some reason, exhibits are disappearing from my list the day before they are supposed to. For example, I have an exhibit whose last day is today, August 24, and its unixtime value is 1535068800. The value for tomorrow, August 25, is 1535155200. The latter value is clearly greater than the former, and so this exhibit should still be included in the query, but it is not.

What am I missing here?

  • I've never seen the date_clause and location_clause syntax before, and I can find no record of it in any of the docs, are you using a custom query modification plugin of some sort? They are definitely not standard WP core options, and aren't listed in the WP_Query documentation – Tom J Nowell Aug 25 '18 at 0:28
  • I came across that as a method for dealing with associative arrays in meta queries here: wordpress.stackexchange.com/questions/246355/…. Do you think this is the source of the problem? It doesn't seem to be. – joakland Aug 27 '18 at 17:17
  • hmm in that case I would cast suspicion on the date clause, you need to be able to tell WP that it's a date/number not a string, and to treat it as such. Additionally you location clause is just a key, with no values or comparisons. Note that a location taxonomy and the post publish date would both be significantly faster by orders of magnitude. You can use pre_get_posts so that all events regardless of publish date are shown, rather than just those in the past – Tom J Nowell Aug 27 '18 at 22:18

Your Answer

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

Browse other questions tagged or ask your own question.