【发布时间】:2019-04-25 05:54:17
【问题描述】:
我试图通过 ACF 转发器字段 ID-s 显示自定义帖子数组。
我只从 $value 中得到一个值,例如:
'post__in' => 数组(905)
但它应该是: 'post__in' => 数组(15, 905, 1, 2, 3)
<?php
if( have_rows('take_away_order') ):
while ( have_rows('take_away_order') ) : the_row();
$value = get_sub_field('food');
?>
<?php endwhile;?>
<?php if (is_tax() || is_category() || is_tag() ){
$qobj = $wp_query->get_queried_object();
$args = array(
'posts_per_page' => 999,
'post_type' => 'menuu_toit',
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => array($value),
'tax_query' => array(
array(
'taxonomy' => $qobj->taxonomy,
'field' => 'id',
'terms' => $qobj->term_id
)
)
);
}
【问题讨论】:
-
您在每次循环迭代中覆盖 $value,当然只有最后一个值以这种方式“存活”。将 $value 设为以数组开头(循环前的
$value = [];),然后在其中添加新元素,$value[] = …也不要array($value),否则你会得到一个数组数组。 -
$value[] = .. - 这应该在 While 中完成?
-
是的,在循环内。
标签: php wordpress advanced-custom-fields