Created
June 18, 2020 20:14
-
-
Save everaldomatias/2df872ed30757e71e88a0ee4e2c9c286 to your computer and use it in GitHub Desktop.
WordPress - Query posts with taxonomy term (NOT EXISTS) and meta value (DATE)
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 | |
$args = [ | |
'post_type' => 'events', | |
'posts_per_page' => -1, | |
'post_status' => 'publish', | |
'tax_query' => [ | |
[ | |
'taxonomy' => 'event_terms', | |
'field' => 'slug', | |
'terms' => 'event_past', | |
'operator' => 'NOT EXISTS', | |
] | |
], | |
'meta_key' => 'events_date', | |
'meta_query' => [ | |
[ | |
'key' => 'events_date', | |
'compare' => '<', | |
'value' => date( 'Ymd' ), | |
'type' => 'DATE' | |
] | |
] | |
]; | |
$posts = new WP_Query( $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment