我正在尝试创建一个自定义循环,其中包含与特定帖子 ID 相关的内容,我从名为“reference_posts”的魔术字段重复文本字段中获取其编号。
当我回显 $testvalue; 它输出正确的帖子列表“20432,43242,34253”,但是当我尝试在数组中输出它时,我只会得到第一个值重复“20432,20432,20432”。
我猜问题是我必须将第二个 foreach 包含在第一个中,但我无法做到这一点。
谁能帮我吗?
<?php
$value = get_field ('reference_posts') ;
foreach ( $value as $my_val ) {
$testvalue = $my_val . ",";
echo $testvalue;
$post_idarray = array( 'post__in' => array( $testvalue ) );
$postspecial = get_posts($post_idarray);
}
foreach( $postspecial as $post ) :
setup_postdata($post);
?>
<div>my content</div>
<?php endforeach; ?>
提前致谢!