^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_metadata()用法示例

get_metadata( string $meta_type,  int $object_id,  string $meta_key = '',  bool $single = false )

Retrieve metadata for the specified object.


描述


参数

$meta_type

(string)
(Required)
Type of object metadata is for (e.g., comment, post, or user)

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$object_id

(int)
(Required)
ID of the object metadata is for

$meta_key

(string)
(Optional)
Metadata key. If not specified, retrieve all metadata for the specified object.

Default value: ”

$single

(bool)
(Optional)
If true, return only the first value of the specified meta_key. This parameter has no effect if meta_key is not specified.

Default value: false


返回值

(mixed) Single metadata value, or array of values


源代码

File: wp-includes/meta.php

function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
	if ( ! $meta_type || ! is_numeric( $object_id ) ) {
		return false;
	}

	$object_id = absint( $object_id );
	if ( ! $object_id ) {
		return false;
	}

	/**
	 * Filters whether to retrieve metadata of a specific type.
	 *
	 * The dynamic portion of the hook, `$meta_type`, refers to the meta
	 * object type (comment, post, or user). Returning a non-null value
	 * will effectively short-circuit the function.
	 *
	 * @since 3.1.0
	 *
	 * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
	 *                                     or an array of values.
	 * @param int               $object_id Object ID.
	 * @param string            $meta_key  Meta key.
	 * @param bool              $single    Whether to return only the first value of the specified $meta_key.
	 */
	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
	if ( null !== $check ) {
		if ( $single && is_array( $check ) )
			return $check[0];
		else
			return $check;
	}

	$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');

	if ( !$meta_cache ) {
		$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
		$meta_cache = $meta_cache[$object_id];
	}

	if ( ! $meta_key ) {
		return $meta_cache;
	}

	if ( isset($meta_cache[$meta_key]) ) {
		if ( $single )
			return maybe_unserialize( $meta_cache[$meta_key][0] );
		else
			return array_map('maybe_unserialize', $meta_cache[$meta_key]);
	}

	if ($single)
		return '';
	else
		return array();
}

更新日志

Version 描述
2.9.0 Introduced.

相关函数

Uses

  • wp-includes/cache.php:
    wp_cache_get()
  • wp-includes/functions.php:
    absint()
  • wp-includes/functions.php:
    maybe_unserialize()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/meta.php:
    update_meta_cache()
  • wp-includes/meta.php:
    get_{$meta_type}_metadata
  • Show 1 more use


Used By

  • wp-includes/rest-api/fields/class-wp-rest-meta-fields.php:
    WP_REST_Meta_Fields::update_multi_meta_value()
  • wp-includes/rest-api/fields/class-wp-rest-meta-fields.php:
    WP_REST_Meta_Fields::update_meta_value()
  • wp-includes/rest-api/fields/class-wp-rest-meta-fields.php:
    WP_REST_Meta_Fields::get_value()
  • wp-includes/meta.php:
    get_registered_metadata()
  • wp-includes/taxonomy.php:
    get_term_meta()
  • wp-includes/user.php:
    get_user_meta()
  • wp-includes/post.php:
    get_post_meta()
  • wp-includes/comment.php:
    get_comment_meta()
  • wp-includes/meta.php:
    update_metadata()
  • Show 4 more used by
    Hide more used by


让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈