Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created June 18, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everaldomatias/2df872ed30757e71e88a0ee4e2c9c286 to your computer and use it in GitHub Desktop.
Save everaldomatias/2df872ed30757e71e88a0ee4e2c9c286 to your computer and use it in GitHub Desktop.
WordPress - Query posts with taxonomy term (NOT EXISTS) and meta value (DATE)
<?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