Support » Fixing WordPress » Meta_compare does not work in query for date comparison
7 years, 2 months ago
I have a custom date field and am trying to pull events between two dates. meta_compare does not have a BETWEEN operator and if I use two meta_compares the first one is ignored.
query_posts($query_string . "&showposts=-1&meta_key=Start%20Date&orderby=meta_value" . "&meta_key=Start%20Date&meta_compare=>=&meta_value=" . date('Y/m/d',$first_day) . "&meta_compare=<=&meta_value=" . date('Y/m/d',$last_day) . "&order=ASC");
As you’ve found, don’t think you can do that. Might need to resort to something similar to the Examples here: http://codex.wordpress.org/wpdb#SELECT_a_Column