1. 首页
  2. WordPress 函数手册

get_posts()

get_posts( array $args = null )

检索与给定条件匹配的最新帖子的数组。
Retrieves an array of the latest posts, or posts matching the given criteria.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

另见函数 WP_Query::parse_query()()


参数(Parameters)

参数 类型 必填 说明
$args (array) 可选 检索帖子的参数。有关所有可用参数,请参见WP_Query::parse_Query()numberposts’(int)要检索的文章总数。是WP_查询中每页$posts_的别名。全部接受-1。默认值5。
‘category'(int|string) Category ID or comma-separated list of IDs (this or any children). Is an alias of $cat in WP_Query. Default 0. ‘include’(array) An array of post IDs to retrieve, sticky posts will be included. Is an alias of $post__in in WP_Query. Default empty array. 可选 “抑制过滤器”(bool)是否抑制过滤器。默认为真。

返回(Return)

(WP_Post[]|int[])Post对象或Post id的数组。


源码(Source)


更新版本 源码位置 使用 被使用
1.2.0 wp-includes/post.php:2014 18 3

笔记(Notes)

返回具有属性的WP_Post对象数组,
获取博客中最新10篇文章的示例:
带有上一个下一个导航的帖子

get_posts() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_posts/