count_user_posts

函数


count_user_posts ( $userid, $post_type = 'post', $public_only = false )
参数
  • (int)
    $userid
    User ID.
    Required:
  • (array|string)
    $post_type
    Optional. Single post type or array of post types to count the number of posts for. Default ‘post’.
    Required:
    Default: ‘post’
  • (bool)
    $public_only
    Optional. Whether to only return counts for public posts. Default false.
    Required:
    Default: false
返回值
  • (string) Number of posts the user has written in this post type.
定义位置
  • wp-includes/user.php
    , line 554
引入
3.0.0
弃用

Gets the number of posts a user has written.

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" );

	/**
	 * Filters the number of posts a user has written.
	 *
	 * @since 2.7.0
	 * @since 4.1.0 Added `$post_type` argument.
	 * @since 4.3.1 Added `$public_only` argument.
	 *
	 * @param int          $count       The user's post count.
	 * @param int          $userid      User ID.
	 * @param string|array $post_type   Single post type or array of 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, $public_only );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。