如果Rol
在meta中,您必须获取所有用户的ID,然后将meta访问rol与用户的rol进行比较:
$post_parent_ID = $post->post_parent ? $post->post_parent : $post->ID;
$title = $post->post_parent ? get_the_title( $post->post_parent ) : get_the_title( $post->ID );
//we use get posts to get all posts for the given ID
$children_pages_array = get_posts(array(\'numberposts\' => -1, \'post_status\' => \'publish\', \'post_type\' => \'any\', \'post_parent\' => $post_parent_ID, \'suppress_filters\' => false));
//we get the user rol
$user_role = sb_get_user_role();
//here we create an array that will be populated with IDs
$ID_pages_rol_array = array();
foreach ($children_pages_array as $child_page_obj) {
//we get the rol that can access this page
$page_role = get_post_meta($child_page_obj->ID, \'_members_access_role\');
//do the current user rol have access to this page?
if ($page_role == $user_role) {
//yes it does add to the IDs of pages that this rol can access
array_push($ID_pages_rol_array, $child_page_obj->ID);
}
}
$children = wp_list_pages(array(
\'title_li\' => \'\',
\'include\' => $ID_pages_rol_array, //lets send those IDs to be formatted as list items
\'echo\' => 0,
\'depth\' => 1
));
您可以使用
get_posts
(实际上是整个post对象)创建允许的ID数组后,可以将其发送到
wp_list_pages
.