返回介绍

update_term_meta()

发布于 2017-09-11 11:06:20 字数 2459 浏览 1296 评论 0 收藏 0

update_term_meta( int $term_id,  string $meta_key,  mixed $meta_value,  mixed $prev_value = '' )

Updates term metadata.


description

Use the $prev_value parameter to differentiate between meta fields with the same key and term ID.

If the meta field for the term does not exist, it will be added.


参数

$term_id

(int) (Required) Term ID.

$meta_key

(string) (Required) Metadata key.

$meta_value

(mixed) (Required) Metadata value.

$prev_value

(mixed) (Optional) Previous value to check before removing.

Default value: ''


返回值

(int|WP_Error|bool) Meta ID if the key didn't previously exist. True on successful update. WP_Error when term_id is ambiguous between taxonomies. False on failure.


源代码

File: wp-includes/taxonomy.php

function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
	// Bail if term meta table is not installed.
	if ( get_option( 'db_version' ) < 34370 ) {
		return false;
	}

	if ( wp_term_is_shared( $term_id ) ) {
		return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id );
	}

	$updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );

	// Bust term query cache.
	if ( $updated ) {
		wp_cache_set( 'last_changed', microtime(), 'terms' );
	}

	return $updated;
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php: wp_term_is_shared()
  • wp-includes/cache.php: wp_cache_set()
  • wp-includes/l10n.php: __()
  • wp-includes/option.php: get_option()
  • wp-includes/meta.php: update_metadata()
  • wp-includes/class-wp-error.php: WP_Error::__construct()
  • Show 1 more use Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文