Adnan Haque
Adnan Haque

Reputation: 184

Wordpress custom query comparing two timestamp meta data

I am trying to query posts by comparing meta value. I have set two meta with the posts. i.e. 'start_date' and 'end_date'. they are stored as UNIX timestamp.

Now I want to query posts on following conditions:

  1. timestamp of current momment is after(greater than) 'start_date'.
  2. timestamp of current momment is before(smaller than) 'end_date'.

In this case, I want both conditions to fulfill. So, I have used 'relation'=>'AND'.

So here is the print_r of the query:

Array
(
   [post_type] => ads
   [meta_query] => Array
       (
           [relation] => AND
           [0] => Array
               (
                   [kye] => start_date
                   [compare] => <=
                   [value] => 1352054503
                   [type] => NUMERIC
               )

           [1] => Array
               (
                   [kye] => end_date
                   [compare] => >=
                   [value] => 1352054503
                   [type] => NUMERIC
               )

       )

)

Note: ads is a custom post type.

And here is meta of a post:

Array
(   
   [start_date] => Array
       (
           [0] => 1352160000
       )

   [end_date] => Array
       (
           [0] => 1352246400
       )

)

I see absolutely no reason why this post should show up. The start date timestamp(1352160000) is bigger than the current timestamp(1352054503). Which breaks condition #1. So, why is this still showing up? What do you think?

Upvotes: 0

Views: 1024

Answers (1)

Michael Lewis
Michael Lewis

Reputation: 4302

In your meta_query, you're using "kye" instead of "key".

Upvotes: 1

Related Questions