函数文档

get_the_author_posts()

💡 云策文档标注

概述

get_the_author_posts() 函数用于获取当前文章作者发布的文章数量。它返回一个整数,表示该作者在指定文章类型下的文章总数。

关键要点

  • 函数返回当前文章作者的文章数量,类型为整数。
  • 内部实现基于 count_user_posts() 函数,结合 get_post() 获取文章数据。
  • 相关函数包括 the_author_posts() 用于显示作者文章数量,count_user_posts() 用于获取用户文章总数。
  • 自 WordPress 1.5.0 版本引入,无后续变更记录。

代码示例

<?php the_author(); ?> has blogged <?php echo get_the_author_posts(); ?> posts

注意事项

如果当前文章不存在,函数返回 0。使用时需确保在文章上下文中调用,以避免意外结果。


📄 原文内容

Retrieves the number of posts by the author of the current post.

Return

int The number of posts by the author.

Source

function get_the_author_posts() {
	$post = get_post();
	if ( ! $post ) {
		return 0;
	}
	return (int) count_user_posts( $post->post_author, $post->post_type );
}

Changelog

Version Description
1.5.0 Introduced.

User Contributed Notes