count_user_posts()

count_user_posts()函数是Wordpress函数,用户已写的帖子数。

count_user_posts( int $userid, array|string $post_type = ‘post’, bool $public_only = false )

参数(Parameters)

参数类型必填说明
$userid(int)必需用户ID。
$post_type(array | string)可选要计算其文章数的单个文章类型或文章类型数组。
$public_only(bool)可选是否只返回公共职位的计数。

返回(Return)

(string)用户在此文章类型中写入的文章数。


源码(Source)

/**
 * Number of posts user has written.
 *
 * @since 3.0.0
 * @since 4.1.0 Added `$post_type` argument.
 * @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array
 *              of post types to `$post_type`.
 *
 * @global wpdb $wpdb WordPress database object for queries.
 *
 * @param int          $userid      User ID.
 * @param array|string $post_type   Optional. Post type(s) to count the number of posts for. Default 'post'.
 * @param bool         $public_only Optional. Whether to only return counts for public posts. Default false.
 * @return int Number of posts the user has written in this post type.
 */
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) {
	global $wpdb;
	$where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
	$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
	/**
	 * Filter the number of posts a user has written.
	 *
	 * @since 2.7.0
	 * @since 4.1.0 Added `$post_type` argument.
	 * @since 4.3.0 Added `$public_only` argument.
	 *
	 * @param int          $count       The user's post count.
	 * @param int          $userid      User ID.
	 * @param string|array $post_types  Post types to count the number of posts for.
	 * @param bool         $public_only Whether to limit counted posts to public posts.
	 */
	return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
}
更新版本源码位置使用被使用
4.3.0wp-includes/user.php:37034

笔记(Notes)

获取用户的帖子计数
获取按投递类型筛选的用户的投递计数
翻译友好职位计数

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索