0

I have this code calling a list of custom post events. It calls them in the right order, but when the event is passed, it stil displays the event. Any ideas what's wrong with the code?

  $args2 = array(
    "post_type" => "gig",
    "meta_key" => "_gigswhen", // Change to the meta key you want to sort by
            "meta_query" => array(
            array(
             "meta_key" => "_gigswhen",
             "value" => date(),
                "compare" => ">=",
           ),
     ),
    "orderby" => "meta_value_num", // This stays as 'meta_value' or 'meta_value_num' (str sorting or numeric sorting)
    "order" => "ASC"
    );

The date in "_gigswhen" is stored as strtotime (unix timecode)

1

You can't use date() with no parameters. See http://php.net/manual/en/function.date.php.

Try this for your meta_query argument:

'meta_query' => array(
    array(
        'key' => '_gigswhen',
        'value' => time()
        'compare' => '<'
    )
)
  • Not quite working.. I should have mentioned that the gig date is stored as a unix time code. – marctain Mar 17 '12 at 4:48
  • I've edited my answer so that it applies to UNIX timestamps. – Boone Gorges Mar 17 '12 at 12:23
  • for some reason, it's just showing all the gigs.. Doesn't seem to be affecting much, my way or yours. – marctain Mar 17 '12 at 17:10
  • I'm afraid it's difficult to debug based on these details. You may consider echoing $this->request just after line 2612 here core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/… in order to see exactly what WP is attempting to fetch. – Boone Gorges Mar 17 '12 at 20:48
  • Also, I just noticed that I wrote meta_key when it should be just key (I think I'd copied what you wrote above). I updated my answer to reflect this. – Boone Gorges Mar 17 '12 at 20:49

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.