在WordPress 4.4中,我们可以使用等待已久的术语元,因此您可以使用它来存储术语的额外信息。
术语Meta API调用包括:
Add term meta:
函数调用:
add_term_meta( $term_id, $meta_key, $meta_value, $unique );
说明:
/**
* Adds metadata to a term.
*
* @since 4.4.0
*
* @param int $term_id Term ID.
* @param string $meta_key Metadata name.
* @param mixed $meta_value Metadata value.
* @param bool $unique Optional. Whether to bail if an entry with the same key is found for the term.
* Default false.
* @return int|WP_Error|bool Meta ID on success. WP_Error when term_id is ambiguous between taxonomies.
* False on failure.
*/
Update term meta:
函数调用:
update_term_meta( $term_id, $meta_key, $meta_value, $prev_value );
说明:
/**
* Updates term metadata.
*
* 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.
*
* @since 4.4.0
*
* @param int $term_id Term ID.
* @param string $meta_key Metadata key.
* @param mixed $meta_value Metadata value.
* @param mixed $prev_value Optional. Previous value to check before removing.
* @return 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.
*/
Delete term meta:
函数调用:
delete_term_meta( $term_id, $meta_key, $meta_value )
说明:
/**
* Removes metadata matching criteria from a term.
*
* @since 4.4.0
*
* @param int $term_id Term ID.
* @param string $meta_key Metadata name.
* @param mixed $meta_value Optional. Metadata value. If provided, rows will only be removed that match the value.
* @return bool True on success, false on failure.
*/