确定是否为给定对象设置了元键

原型

metadata_exists( string $meta_type, int $object_id, string $meta_key )

参数

$meta_type (string) (Required) 对象元数据的类型用于(例如,评论,帖子,术语或用户)。

$object_id (int) (Required) 对象元数据的ID用于

$meta_key (string) (Required) 元数据键。

返回值

(bool)  设置密钥的真,否则为假。

源文件

路径:wp-includes/meta.php

<?php
...
function metadata_exists( $meta_type, $object_id, $meta_key ) {
	if ( ! $meta_type || ! is_numeric( $object_id ) ) {
		return false;
	}
	$object_id = absint( $object_id );
	if ( ! $object_id ) {
		return false;
	}
	/** This filter is documented in wp-includes/meta.php */
	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );
	if ( null !== $check )
		return (bool) $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 ( isset( $meta_cache[ $meta_key ] ) )
		return true;
	return false;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/metadata_exists/