функция
since 3.6.0
get_attached_media()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_attached_media( string $type, int|WP_Post $post ): WP_Post[]
Описание
Получает медиафайлы, прикреплённые к переданной записи.
Параметры
$type
string
обязательный
MIME-тип.
$post
int|WP_Post
необязательный
ID записи или объект WP_Post. По умолчанию — глобальная переменная $post.
Возвращаемое значение
WP_Post[]
Исходный код
wp-includes/media.php:5164
function get_attached_media( $type, $post = 0 ) {
$post = get_post( $post );
if ( ! $post ) {
return array();
}
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => $type,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
/**
* Filters arguments used to retrieve media attached to the given post.
*
* @since 3.6.0
*
* @param array $args Post query arguments.
* @param string $type Mime type of the desired media.
* @param WP_Post $post Post object.
*/
$args = apply_filters( 'get_attached_media_args', $args, $type, $post );
$children = get_children( $args );
/**
* Filters the list of media attached to the given post.
*
* @since 3.6.0
*
* @param WP_Post[] $children Array of media attached to the given post.
* @param string $type Mime type of the media desired.
* @param WP_Post $post Post object.
*/
return (array) apply_filters( 'get_attached_media', $children, $type, $post );
}
История изменений
| Версия | Описание |
|---|---|
| 3.6.0 | Introduced. |

