I’m working on a games release feature for a website I’m building. So far everything is going smooth, but I’m stuck on one area. For the listings on the front end, I want it to look at the “release_date” field and only display games that have a release date >= that date.
I feel the code below should work, but it doesn’t return/display anything on the front end. And if I switch it to <=, it displays everything.
Any help would be greatly appreciated! Below is the query code.
$releasewindow = date('M j, Y', strtotime("-31 days")); $q = new WP_Query(array( 'post_type' => 'game_release', 'posts_per_page' => 5, 'meta_key' => 'release_date', 'orderby' => 'release_date', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'release_date', 'compare' => '>=', 'value' => $releasewindow, ) ),
M j, Yis a pretty strange format to store a date in - is that what the format actually is in the database?
YYYY-MM-DDformat or stored as a timestamp. What's happening with your current code is the SQL is just executing a standard alphanumeric comparison - so dates are getting ordered more or less by the abbreviated name of the month. Would it be permissible for you to add a second meta-field storing the same date in a more workable format?