2

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 1

1

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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