wp_get_recent_posts()
wp_get_recent_posts( array $args = array(), string $out…
wp_get_recent_posts( array $args = array(), string $output = ARRAY_A )
检索一些最近的帖子。
Retrieve a number of recent posts.
目录锚点:#说明#参数#源码#笔记
说明(Description)
另请参见get_posts()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $args | (array) | 检索帖子的参数。 |
| $output | (string) | 所需的返回类型。对象或数组之一,分别对应于WP_Post对象或关联数组。 |
源码(Source)
/**
* Retrieve a number of recent posts.
*
* @since 1.0.0
*
* @see get_posts()
*
* @param array $args Optional. Arguments to retrieve posts. Default empty array.
* @param string $output Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
* @return array|false Associative array if $output equals ARRAY_A, array or false if no results.
*/
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
if ( is_numeric( $args ) ) {
_deprecated_argument( __FUNCTION__, '3.1', __( '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
);
$r = wp_parse_args( $args, $defaults );
$results = get_posts( $r );
// 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;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.0.0 | wp-includes/post.php | 13 | 5 |
笔记(Notes)
有限的最近的文章和标题缩略图
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!