update_term_meta

函数
update_term_meta ( $term_id, $meta_key, $meta_value, $prev_value = '' )
参数
  • (int) $term_id Term ID.
    Required:
  • (string) $meta_key Metadata key.
    Required:
  • (mixed) $meta_value Metadata value. Must be serializable if non-scalar.
    Required:
  • (mixed) $prev_value Optional. Previous value to check before updating. If specified, only update existing metadata entries with this value. Otherwise, update all entries. Default empty.
    Required:
    Default: (empty)
返回值
  • (int|bool|WP_Error) Meta ID if the key didn't exist. true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database. WP_Error when term_id is ambiguous between taxonomies.
定义位置
相关方法
update_site_metaupdate_user_metaupdate_usermetadelete_term_metaupdate_termmeta_cache
引入
4.4.0
弃用
-

update_term_meta: 这个函数更新一个分类法术语的元数据。它接收术语的ID和元数据的键和值来更新。

更新术语元数据。

使用`$prev_value`参数来区分具有相同键和术语ID的元域。

如果该术语的元字段不存在,它将被添加。

function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
	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 );
	}

	return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
}

常见问题

FAQs
查看更多 >