get_attached_media 获取附加的某篇文章的多附件媒体

Posted in:
Update time:2020-10-29

函数描述

获取附加到当前文章或指定文章的多媒体附件。

Usage

<?php get_attached_media( $type, $post_id ) ?>

parameters

parametersdata typeRequired or notdescriptivedefault value
$typestring (computer science)be 需要获取的多媒体的mime类型not have
$post_idinteger (math.)clogged文章ID,默认为当前文章ID0

return value

数组,获取到的附件的 WP_Post 对象。

usage example

获取当前文章的图片附件:

$media = get_attached_media( 'image' );

获取 ID 为 102 的文章的音频附件:

$media = get_attached_media( 'audio', 102 );

We offer WordPress Themes and Plugins Custom Development Services

This site has long undertaken WordPress themes, plugins, WooCommerce-based store mall development business. We have 10 years of experience in WordPress development, if you want to Developing Websites with WordPress, please contact WeChat: iwillhappy1314 or email: amos@wpcio.com for inquiries.

发表回复

Your email address will not be published. 必填项已用 * 标注

*