Last active
December 1, 2021 10:48
-
-
Save zeshanshani/842c14baeb42d33ce90d1d1bf7a5de68 to your computer and use it in GitHub Desktop.
WP_Query 'meta_query' for "Date Start" and "Date End" custom fields. Conditions are (relation = 'OR'): 1. If "Date End" does not exist, compare "Date Start" only.
2. If "Date End" exists, show events in between that and "Date Start".
This file contains hidden or 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 | |
/** | |
* WP_Query 'meta_query' for "Date Start" and "Date End" custom fields. | |
* Conditions are (relation = 'OR'): | |
* 1. If "Date End" does not exist, compare "Date Start" only. | |
* 2. If "Date End" exists, show events in between that and "Date Start". | |
*/ | |
'meta_query' => array( | |
'relation' => 'OR', | |
array( | |
'key' => 'date_start', | |
'value' => date( 'Ymd' ), | |
'compare' => '=', | |
'type' => 'date' | |
), | |
array( | |
'relation' => 'AND', | |
array( | |
'key' => 'date_start', | |
'value' => date( 'Ymd' ), | |
'compare' => '<=', | |
'type' => 'date' | |
), | |
array( | |
'key' => 'date_end', | |
'value' => date( 'Ymd' ), | |
'compare' => '>=', | |
'type' => 'date' | |
), | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment