Skip to content

Instantly share code, notes, and snippets.

@Tmeister
Last active June 3, 2022 23:27
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 Tmeister/4096885f0b622d4031cd1afc6fb6c864 to your computer and use it in GitHub Desktop.
Save Tmeister/4096885f0b622d4031cd1afc6fb6c864 to your computer and use it in GitHub Desktop.
A simple sample to query two Custom Post Types with a tax_query
<?php
$args = [
'post_type' => ['post', 'work'],
'posts_per_page' => -1,
'tax_query' => [
'relation' => 'OR',
[
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => 'tag-two'
],
[
'taxonomy' => 'category',
'operator' => 'NOT EXISTS'
]
]
];
$posts = new WP_Query($args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment