Skip to content

Instantly share code, notes, and snippets.

@muddasirawan
Forked from elvismdev/single-author.php
Created August 31, 2018 15:17
Show Gist options
  • Save muddasirawan/e0bc96b13f5f011dc986f8427a737908 to your computer and use it in GitHub Desktop.
Save muddasirawan/e0bc96b13f5f011dc986f8427a737908 to your computer and use it in GitHub Desktop.
Combine tax_query and meta_query in WP_Query()
<?php
/**
* This is a kind of rare combination of arguments for WP_Query(), needed in some very special cases.
* This is an already tested snippet code that works!
*/
// Bring post from the global context (if not present already).
global $post;
// Define the post_type's to query for.
$post_types = array( 'event', 'post', 'book' );
// Do the weird query. Play with, or add arguments as needed https://codex.wordpress.org/Class_Reference/WP_Query
$results = WP_Query(
array(
'post_type' => $post_types,
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => wp_get_post_categories( $post->ID )
)
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'presenters_people',
'value' => $post->ID,
'compare' => 'LIKE'
),
array(
'key' => 'author',
'value' => $post->ID,
'compare' => 'LIKE'
)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment