我有一个循环来获取分类的术语列表。
<?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 = array();
...
foreach( $terms as $term ) {
$termoutput[] = $term->slug;
}
然后,在代码的第二部分:
...
'terms' => $termoutput
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句