I need to figure out how to query posts by the following conditions: if they are in the category (by ID) or if they have a taxonomy term. So that on one archive page, I have all posts with a category ID of 12, and all posts that have the taxonomy term 'archive-trading-tools' I have set up custom taxonomy and that part is working. I am stuck at:
<?php
$query_args = array(
'post_type' => array('post', 'webinar'),
'posts_per_page' => 10,
'paged' => $paged,
'page' => $paged,
'cat' => 12,
//'relation' => 'OR'
);
$query_args['tax_query'] = array (
'taxonomy' => 'archive-categories',
'term' => 'archive-trading-tools'
);
$the_query = new WP_Query( $query_args );
?>
In WordPress a category is a built-in taxonomy. Then in theory, the following should work.
$args = array(
'post_type' => array('post', 'webinar'),
'posts_per_page' => 10,
'paged' => $paged,
'page' => $paged,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'archive-categories',
'field' => 'slug'
'terms' => 'archive-trading-tools',
),
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => 12
)
)
);
$query = new WP_Query( $args );
To expand on @depiction's answer, you the 'terms' in the tax_query should be "term" instead of "terms". No 's at the end.
$args = array(
'post_type' => array('post', 'webinar'),
'posts_per_page' => 10,
'paged' => $paged,
'page' => $paged,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'archive-categories',
'field' => 'slug'
'terms' => 'archive-trading-tools',
),
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => 12
)
)
);
$query = new WP_Query( $args );