Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.