In your code $atts
is always $atts = [ 'category' => '' ]
, you cannot use 'terms' => $atts,
in query parameters $query_args
.
[litters category="first_slug,second_slug"]
You can assign to 'terms'
in 'tax_query'
parameter a string (single category) or an array (multiple category). $args['category']
is passed to the shortcode function as string, so you need to check if it’s one category and no action is required, or a list of slugs separated by commas and they must be converted to an array.
public function shortcode_litters( $args ) {
$output="";
//
// filter shortcode attributes
$args = shortcode_atts(
array( 'category' => '', 'columns' => '' ),
$args
);
if ( strpos( $args['category'], ',' ) !== false ) {
$terms = explode( ',', $args['category'] );
} else {
$terms = $args['category'];
}
$query_args = array(
'post_type' => 'litter',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'asc',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'product_category',
'field' => 'slug',
'terms' => $terms,
),
),
);