您可以使用edit_posts_per_page
挂钩或edit_{$post_type}_per_page
页面和自定义帖子类型的挂钩
您可以根据用户角色进行更改:
function my_edit_post_per_page_role_based( $per_page, $post_type ) {
//admin sees 25 posts per page
if (current_user_can(\'administrator\')){return 25;}
//editor sees 20 posts per page
elseif(current_user_can(\'editor\')){return 15;}
//author sees 10 posts per page
elseif(current_user_can(\'author\')){return 10;}
//contributor sees 5 posts per page
elseif(current_user_can(\'contributor\')){return 5;}
return $per_page;
}
add_filter( \'edit_posts_per_page\', \'my_edit_post_per_page_role_based\' );
或根据用户id进行更改:
function my_edit_post_per_page_user_based( $per_page, $post_type ) {
global $current_user;
get_currentuserinfo();
//specific user id ex: user with the ID of 23
if (23 == $current_user->ID){
return 20;
}
//user group
$can_see_only_10 = array(2,5,36,55,47); //array holding the group ids
if (in_array($current_user->ID,$can_see_only_10)){
return 10;
}
return $per_page;
}
add_filter( \'edit_posts_per_page\', \'my_edit_post_per_page_user_based\' );