функция
since 1.0.0
wp_get_recent_posts()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_get_recent_posts( array $args = array(), string $output = ARRAY_A ): array|false
Описание
См. alsoget_posts()
Оригинал (английский)
Параметры
$args
array
необязательный
= array()
Аргументы для получения записей.
$output
string
необязательный
= ARRAY_A
Требуемый тип возвращаемого значения. Одно из OBJECT или ARRAY_A, что соответствует объекту WP_Post или ассоциативному массиву соответственно.
Возвращаемое значение
array|false
$output
Исходный код
wp-includes/post.php:4397
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;
}
История изменений
| Версия | Описание |
|---|---|
| 1.0.0 | Introduced. |

