get_private_posts_cap_sql()
云策文档标注
概述
get_private_posts_cap_sql() 函数基于用户能力生成用于筛选私有文章的 SQL 代码片段,适用于 WordPress 开发者构建查询条件。
关键要点
- 函数返回 SQL 代码片段,可添加到 WHERE 子句中,用于选择所有已发布文章和用户有权限访问的私有文章。
- 参数 $post_type 支持字符串或数组,目前仅支持 'post' 或 'page'。
- 该函数内部调用 get_posts_by_author_sql() 实现,简化了基于能力的文章筛选逻辑。
- 从 WordPress 4.3.0 版本开始,$post_type 参数支持数组形式。
原文内容
Retrieves the private post SQL based on capability.
Description
This function provides a standardized way to appropriately select on the post_status of a post type. The function will return a piece of SQL code that can be added to a WHERE clause; this SQL is constructed to allow all published posts, and all private posts to which the user has access.
Parameters
$post_typestring|arrayrequired-
Single post type or an array of post types. Currently only supports
'post'or'page'.
Source
function get_private_posts_cap_sql( $post_type ) {
return get_posts_by_author_sql( $post_type, false );
}