get_enclosed()获取文章中所有的附件

目录

描述

译文

检索文章中已有enclosures。

原文

Retrieve enclosures already enclosed for a post.

get_enclosed() 描述

用法

<?php get_enclosed$post_id ?>

get_enclosed() 用法

参数

$post_id

(integer) (必填) Post ID.

默认值: None

get_enclosed() 参数

返回值

(array) 

List of enclosures.

get_enclosed() 返回值

注意

get_enclosed() 注意

历史

添加于 版本: 1.5.0

get_enclosed() 历史

源文件

get_enclosed() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve enclosures already enclosed for a post.
 *
 * @since 1.5.0
 *
 * @param int $post_id Post ID.
 * @return array List of enclosures.
 */
function get_enclosed( $post_id ) {
	$custom_fields = get_post_custom( $post_id );
	$pung = array();
	if ( !is_array( $custom_fields ) )
		return $pung;

	foreach ( $custom_fields as $key => $val ) {
		if ( 'enclosure' != $key || !is_array( $val ) )
			continue;
		foreach( $val as $enc ) {
			$enclosure = explode( "
", $enc );
			$pung[] = trim( $enclosure[ 0 ] );
		}
	}

	/**
	 * Filter the list of enclosures already enclosed for the given post.
	 *
	 * @since 2.0.0
	 *
	 * @param array $pung    Array of enclosures for the given post.
	 * @param int   $post_id Post ID.
	 */
	return apply_filters( 'get_enclosed', $pung, $post_id );
}

get_enclosed() 源文件