我假设您(或用户)将在posts自定义字段中输入post ID,以逗号分隔,例如:11,13,34,54
或11, 13, 34, 54
.
然后,您需要做的就是为加载的帖子获取自定义字段值,用逗号(,)分解自定义字段值:然后,您将有一个很好的数组传递到include
参数以下是一个显示重要部分的示例:
<?php
$postIds = get_post_meta($post->ID, \'postIds\', true); // get custom field value
$arrayIds = explode(\',\', $postIds); // explode value into an array of ids
if(count($arrayIds) <= 1) // if array contains one element or less, there\'s spaces after comma\'s, or you only entered one id
{
if( strpos($arrayIds[0], \',\') !== false )// if the first array value has commas, there were spaces after ids entered
{
$arrayIds = array(); // reset array
$arrayIds = explode(\', \', $postIds); // explode ids with space after comma\'s
}
}
$args = array(
\'include\' => $arrayIds // pass array of ids into `include` parameter
);
...
?>