我有一個循環來獲取分類的術語列表。將循環輸出保存到變量中
<?php
$terms = get_field('modell');
if($terms):
$total = count($terms);
$count = 1;
foreach($terms as $term):
?>
'<?php echo $term->slug; ?>'
<?php
if ($count < $total) {
echo ', ';
}
$count++;
endforeach;
endif;
?>
迴路輸出是這樣的:
'termname-one','termname-two','termname-three'
現在我要救這個輸出到變量($ termoutput),並將其插入到下面的循環方面的數組:
<?php
query_posts(array(
'post_type' => 'posttypename',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'systems',
'field' => 'slug',
'terms' => array($termoutput)
)
)
)); ?>
有沒有辦法實現這個?謝謝!
'$ termoutput = [];'在foreach之前。然後在循環中使用'$ termoutput [] = $ term-> slug;'......這就是字面意思。 – naththedeveloper