wordpress media.php,wordpress函数get_attached_media()用法示例

get_attached_media( string $type, int|WP_Post $post )

Retrieves media attached to the passed post.

描述

参数

$type

(string)

(Required)

Mime type.

$post

(int|WP_Post)

(Optional)

Post ID or WP_Post object. Default is global $post.

返回值

(array) Found attachments.

源代码

File: wp-includes/media.php

function get_attached_media( $type, $post = 0 ) {

if ( ! $post = get_post( $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 mixed $post Post ID or 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 array $children Associative array of media attached to the given post.

* @param string $type Mime type of the media desired.

* @param mixed $post Post ID or object.

*/

return (array) apply_filters( 'get_attached_media', $children, $type, $post );

}

更新日志

Version

描述

3.6.0

Introduced.

相关函数

Uses

wp-includes/post.php:

get_children()

wp-includes/plugin.php:

apply_filters()

wp-includes/media.php:

get_attached_media

wp-includes/media.php:

get_attached_media_args

wp-includes/post.php:

get_post()

Used By

wp-includes/media.php:

wp_video_shortcode()

wp-includes/media.php:

wp_audio_shortcode()

User Contributed Notes

Skip to note content

You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

Contributed by Jules Colle

You can get all attached media, regardless of type, by passing an empty string:

$media = get_attached_media( '' );

or

$media = get_attached_media( '', 102 );

Examples

Get image attachment(s) to the current Post:

$media = get_attached_media( 'image' );

Get attachment(s) of mime-type ‘audio’ to the Post with an ID of 102:

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

It should be noted, that this function returns array of WP_Post objects, indexed by their ID, ordered by their “menu order” by default – that is where usually plugins handling attachment store their order positions…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include "lib_prot_pd.h" #include "mod_input_output.h" #include "mod_display.h" #include "mod_queue.h" #include "app_typec_deal.h" #include "app_init.h" #include "lib_multi_protocol.h" uint8_t typeca_ufp= 0; void typeca_hard_reset_cb(void) { static uint8_t b_typec_hard_reset_lock= RESET; if(h_pd.output.b_source_read_hard|| \ h_pd.output.b_sink_read_hard) { if(b_typec_hard_reset_lock== RESET) { b_typec_hard_reset_lock= SET; mod_queue_send(PLUG_CA_RST_P); } }else { if(b_typec_hard_reset_lock) { b_typec_hard_reset_lock= RESET; mod_queue_send(PLUG_CA_RST_N); } } } void typecb_hard_reset_cb(void) { static uint8_t b_typec_hard_reset_lock= RESET; if(h_pd.output.b_source_read_hard|| \ h_pd.output.b_sink_read_hard) { if(b_typec_hard_reset_lock== RESET) { b_typec_hard_reset_lock= SET; mod_queue_send(PLUG_CB_RST_P); } }else { if(b_typec_hard_reset_lock) { b_typec_hard_reset_lock= RESET; mod_queue_send(PLUG_CB_RST_N); } } } void typeca_pr_swap_cb(void) { static uint8_t b_pd_power_role_swap_lock; if(h_pd.output.b_pr_swap_en) { if(h_pd.output.b_source_read_pr_swap) { b_pd_power_role_swap_lock= SET; /*用户代码*/ //关 VBus }else if(h_pd.output.b_sink_read_pr_swap) { /*用户代码*/ //DC-DC 进入放电状态,升压,打开 VBus } }else { b_pd_power_role_swap_lock= RESET; } } void typecb_pr_swap_cb(void) { static uint8_t b_pd_power_role_swap_lock; if(h_pd.output.b_pr_swap_en) { if(h_pd.output.b_source_read_pr_swap) { b_pd_power_role_swap_lock= SET; /*用户代码*/ //关 VBus }else if(h_pd.output.b_sink_read_pr_swap) { /*用户代码*/ //DC-DC 进入放电状态,升压,打开 VBus } }else { b_pd_power_role_swap_lock= RESET; } } bool typeca_vbus_exist_cb(void) { //判断一下0.8V VBus电压 return mod_io_typeca_acin(); } bool typecb_vbus_exist_cb(void) { //判断一下0.8V VBus电压 return mod_io_typecb_acin(); } void typeca_attached_src_cb(void) { /** * !!! * 兼容性测试需要 */ mod_io_a1d_out(); mod_queue_send(PLUG_CAD_IN); } void typecb_attached_src_cb(void) { mod_io_a1d_out(); mod_queue_send(PLUG_CBD_IN); } void typeca_attached_snk_cb(void) { mod_queue_send(PLUG_CAC_IN); typeca_ufp = 1; } void typecb_attached_snk_cb(void) { mod_queue_send(PLUG_CBC_IN); typeca_ufp = 1; } void typeca_unattached_cb(void) { mod_queue_send(PLUG_CAX_OUT); typeca_ufp = 0; } void typecb_unattached_cb(void) { mod_queue_send(PLUG_CBX_OUT); }
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值