【发布时间】:2017-10-18 20:15:55
【问题描述】:
我有一个循环来获取分类的术语列表。
<?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 之前。然后在你的循环中而不是 echo 使用$termoutput[] = $term->slug;... 就是字面意思。
标签: php wordpress advanced-custom-fields