Created
October 28, 2022 15:15
-
-
Save someguy9/d45d55d479fffa6502caa8ea54a054dd to your computer and use it in GitHub Desktop.
Using meta_query to query posts between dates in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$meta_query_args = array( | |
'meta_query' => array( | |
array( | |
'key' => 'my_date_field', | |
'value' => array( '2022-01-01', '2022-12-31' ), | |
'type' => 'date', | |
'compare' => 'BETWEEN' | |
) | |
) | |
); | |
$meta_query = new WP_Query( $meta_query_args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment