# get_posts()

URL: https://chugunov.pro/api-wordpress/functions/get_posts/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 1.2.0.

## Сигнатура

```php
get_posts( array|string $args = null ): WP_Post[]|int[]
```

## Описание

For more information on the accepted arguments, see the [ WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) documentation in the Developer Handbook.

The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by this function and both are set to `true`.

The defaults are as follows:[See also](#see-also)
- [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)

- [WP_Query::parse_query()](https://developer.wordpress.org/reference/classes/WP_Query/parse_query/)

## Параметры

- `$args` `array|string` — необязательный, по умолчанию `null`. Array or query string of arguments to retrieve posts.
  
  See [WP_Query::parse_query()](https://developer.wordpress.org/reference/classes/wp_query/parse_query/) for all available arguments.
  
  - `numberposts` int Total number of posts to retrieve. Is an alias of `$posts_per_page` in [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/). Accepts -1 for all. Default 5.
  
  - `category` int|string Category ID or comma-separated list of IDs (this or any children).
  
  Is an alias of `$cat` in [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/). Default 0.
  
  - `include` int[] An array of post IDs to retrieve, sticky posts will be included.
  
  Is an alias of `$post__in` in [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/).
  
  - `exclude` int[] An array of post IDs not to retrieve.
  
  - `suppress_filters` bool Whether to suppress filters. Default true.

## Возвращаемое значение

`WP_Post[]|int[]`

## Исходный код

Файл: `wp-includes/post.php:2582`

```php
function get_posts( $args = null ) {
	$defaults = array(
		'numberposts'      => 5,
		'category'         => 0,
		'orderby'          => 'date',
		'order'            => 'DESC',
		'include'          => array(),
		'exclude'          => array(),
		'meta_key'         => '',
		'meta_value'       => '',
		'post_type'        => 'post',
		'suppress_filters' => true,
	);

	$parsed_args = wp_parse_args( $args, $defaults );
	if ( empty( $parsed_args['post_status'] ) ) {
		$parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish';
	}
	if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
		$parsed_args['posts_per_page'] = $parsed_args['numberposts'];
	}
	if ( ! empty( $parsed_args['category'] ) ) {
		$parsed_args['cat'] = $parsed_args['category'];
	}
	if ( ! empty( $parsed_args['include'] ) ) {
		$incposts                      = wp_parse_id_list( $parsed_args['include'] );
		$parsed_args['posts_per_page'] = count( $incposts );  // Only the number of posts included.
		$parsed_args['post__in']       = $incposts;
	} elseif ( ! empty( $parsed_args['exclude'] ) ) {
		$parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] );
	}

	$parsed_args['ignore_sticky_posts'] = true;
	$parsed_args['no_found_rows']       = true;

	$get_posts = new WP_Query();
	return $get_posts->query( $parsed_args );
}
```

## История изменений

- 1.2.0 — Introduced.

## Связанные

Использует: `WP_Query::__construct`, [`wp_parse_id_list`](https://chugunov.pro/api-wordpress/functions/wp_parse_id_list/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/).
Используется в: `WP_Sync_Post_Meta_Storage::get_storage_post_id`, [`do_all_trackbacks`](https://chugunov.pro/api-wordpress/functions/do_all_trackbacks/), [`do_all_enclosures`](https://chugunov.pro/api-wordpress/functions/do_all_enclosures/), [`do_all_pingbacks`](https://chugunov.pro/api-wordpress/functions/do_all_pingbacks/), `WP_Customize_Manager::get_changeset_posts`, [`wp_add_trashed_suffix_to_post_name_for_trashed_posts`](https://chugunov.pro/api-wordpress/functions/wp_add_trashed_suffix_to_post_name_for_trashed_posts/), `WP_Customize_Nav_Menus::load_available_items_query`, [`get_children`](https://chugunov.pro/api-wordpress/functions/get_children/), [`wp_generate_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_generate_attachment_metadata/), [`wp_dashboard_recent_drafts`](https://chugunov.pro/api-wordpress/functions/wp_dashboard_recent_drafts/), [`wp_ajax_find_posts`](https://chugunov.pro/api-wordpress/functions/wp_ajax_find_posts/), [`wp_nav_menu_item_post_type_meta_box`](https://chugunov.pro/api-wordpress/functions/wp_nav_menu_item_post_type_meta_box/), [`get_uploaded_header_images`](https://chugunov.pro/api-wordpress/functions/get_uploaded_header_images/), `WP_Query::get_posts`, [`get_boundary_post`](https://chugunov.pro/api-wordpress/functions/get_boundary_post/), [`gallery_shortcode`](https://chugunov.pro/api-wordpress/functions/gallery_shortcode/), [`wp_playlist_shortcode`](https://chugunov.pro/api-wordpress/functions/wp_playlist_shortcode/), [`wp_get_recent_posts`](https://chugunov.pro/api-wordpress/functions/wp_get_recent_posts/), [`wp_get_nav_menu_items`](https://chugunov.pro/api-wordpress/functions/wp_get_nav_menu_items/), `wp_xmlrpc_server::wp_getMediaLibrary`, `wp_xmlrpc_server::wp_getPages`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_posts/
