我正在尝试使用插件PrivateContent来限制对某些页面/类别的访问。我有一个函数(getAllowedCategories()),它读取当前用户的私有内容访问级别,并输出用户有权访问的类别ID列表。我试图用它来构建一个foreach()循环,将每个ID传递给一个WP\\u查询,并生成该类别中最新的两篇文章。但当我尝试使用变量作为WP\\u查询的参数时,它根本不进行过滤。这是我的代码:
<?php
$currentCats = getAllowedCategories($user_data);
foreach ($currentCats as $currentCat) {
echo $currentCat . "<br/>";
$parameters = "\'category__in=" . $currentCat . "\'";
$aj_query = new WP_Query( $parameters );
if ( $aj_query->have_posts() ) {
echo \'<ul>\';
while ( $aj_query->have_posts() ) {
$aj_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
}
echo \'</ul>\';
}
wp_reset_postdata();
}
?>