Anyone know how I can neatly combine a query to pull CPT by a custom taxonomy and also standard posts by taxonomy into same query to list all posts together on my home page?
for example:
$args = array(
'post_type' => array( 'artists', 'post' ),
'post_status' => 'publish',
'tag_artists' => 'home', // cpt custom taxonomy ##
'tag' => 'home', // standard post type taxonomy ##
);
$query = new WP_Query( $args );
This is clearly wrong as it finds zero results..
1 Answer
here is the answer:
$args = array(
'post_type' => array( 'artists', 'post' ),
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'tag_artists',
'field' => 'slug',
'terms' => array( 'home' )
),
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => array( 'home' )
)
)
);
$query = new WP_Query( $args );