wp_update_attachment_metadata

函数
wp_update_attachment_metadata ( $attachment_id, $data )
参数
  • (int) $attachment_id Attachment post ID.
    Required:
  • (array) $data Attachment meta data.
    Required:
返回值
  • (int|false) False if $post is invalid.
定义位置
相关方法
wp_get_attachment_metadatawp_generate_attachment_metadatawp_maybe_generate_attachment_metadataupdate_comment_metawp_delete_attachment
引入
2.1.0
弃用
-

wp_update_attachment_metadata: 这个函数更新与一个附件相关的元数据。元数据存储在WordPress的数据库中,包括诸如文件的大小、图片的尺寸和文件的MIME类型等信息。

更新一个附件的元数据。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_update_attachment_metadata( $attachment_id, $data ) {
$attachment_id = (int) $attachment_id;
$post = get_post( $attachment_id );
if ( ! $post ) {
return false;
}
/**
* Filters the updated attachment meta data.
*
* @since 2.1.0
*
* @param array $data Array of updated attachment meta data.
* @param int $attachment_id Attachment post ID.
*/
$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
if ( $data ) {
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
} else {
return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
}
}
function wp_update_attachment_metadata( $attachment_id, $data ) { $attachment_id = (int) $attachment_id; $post = get_post( $attachment_id ); if ( ! $post ) { return false; } /** * Filters the updated attachment meta data. * * @since 2.1.0 * * @param array $data Array of updated attachment meta data. * @param int $attachment_id Attachment post ID. */ $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ); if ( $data ) { return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); } else { return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); } }
function wp_update_attachment_metadata( $attachment_id, $data ) {
	$attachment_id = (int) $attachment_id;

	$post = get_post( $attachment_id );

	if ( ! $post ) {
		return false;
	}

	/**
	 * Filters the updated attachment meta data.
	 *
	 * @since 2.1.0
	 *
	 * @param array $data          Array of updated attachment meta data.
	 * @param int   $attachment_id Attachment post ID.
	 */
	$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
	if ( $data ) {
		return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
	} else {
		return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
	}
}

常见问题

FAQs
查看更多 >