Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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..

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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 );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.