wp_get_recent_posts
函数
wp_get_recent_posts ( $args = array(), $output = ARRAY_A )
- 参数
-
-
(array)
$args
Optional. Arguments to retrieve posts. Default empty array.- Required: 否
- Default: array()
-
(string)
$output
Optional. The required return type. One of OBJECT or ARRAY_A, which correspond to a WP_Post object or an associative array, respectively. Default ARRAY_A.- Required: 否
- Default: ARRAY_A
-
(array)
- 返回值
-
- (array|false) Array of recent posts, where the type of each element is determined by the `$output` parameter. Empty array on failure.
- 相关
-
- get_posts()
- 定义位置
-
-
wp-includes/post.php
, line 3931
-
wp-includes/post.php
- 引入
- 1.0.0
- 弃用
- –
检索一些最近的文章。
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
if ( is_numeric( $args ) ) {
_deprecated_argument( __FUNCTION__, '3.1.0', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) );
$args = array( 'numberposts' => absint( $args ) );
}
// Set default arguments.
$defaults = array(
'numberposts' => 10,
'offset' => 0,
'category' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_status' => 'draft, publish, future, pending, private',
'suppress_filters' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$results = get_posts( $parsed_args );
// Backward compatibility. Prior to 3.1 expected posts to be returned in array.
if ( ARRAY_A === $output ) {
foreach ( $results as $key => $result ) {
$results[ $key ] = get_object_vars( $result );
}
return $results ? $results : array();
}
return $results ? $results : false;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


