I want to make a custom WP_Query using custom taxonomy terms ID´s.
Example of the term’s ID’s : 19,18,214,226,20
Why does this work:
$query_args = array (
'post_type' => 'works’,
'tax_query' => array(
array(
'taxonomy' => 'materials',
'field' => 'term_id',
'terms' => array( 19,18,214,226,20 ),
)
),
);
It shows all items from all taxonomy terms ID’s,
But this doesn’t:
$tax = '19,18,214,226,20';
$query_args = array (
'post_type' => 'works',
'tax_query' => array(
array(
'taxonomy' => 'materials',
'field' => 'term_id',
'terms' => array( $tax ),
)
),
);
Using the variable $tax
the query result only shows items the first term ID (19), and ignores all the others.
Why does this happens and how can i use the variable in the tax_query instead of hardcode the ID’s ?