分類法の用語リストを取得するループがあります。ループ出力を変数に保存する
<?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 []を$ TERM->スラグを格納します
<?php
$terms = get_field('modell');
if($terms):
$total = count($terms);
$count = 1;
$termoutput = array();
foreach($terms as $term):
echo "'".$term->slug."'";
$termoutput[] = $term->slug;
if ($count < $total) {
echo ', ';
}
$count++;
endforeach;
endif;
?>
<?php
query_posts(array(
'post_type' => 'posttypename',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'systems',
'field' => 'slug',
'terms' => $termoutput
)
)
));
?>
:
'$ termoutput = [];' foreachの前に。 echoの代わりにループ内で '$ termoutput [] = $ term-> slug;' ...それは文字通りです。 – naththedeveloper