| | 2002 | // Taxonomy meta functions |
| | 2003 | // |
| | 2004 | |
| | 2005 | /** |
| | 2006 | * Add meta data field to a term. |
| | 2007 | * |
| | 2008 | * @since 3.0 |
| | 2009 | * @uses add_metadata |
| | 2010 | * @link http://codex.wordpress.org/Function_Reference/add_term_meta |
| | 2011 | * |
| | 2012 | * @param int $term_id Post ID. |
| | 2013 | * @param string $key Metadata name. |
| | 2014 | * @param mixed $value Metadata value. |
| | 2015 | * @param bool $unique Optional, default is false. Whether the same key should not be added. |
| | 2016 | * @return bool False for failure. True for success. |
| | 2017 | */ |
| | 2018 | function add_term_meta($term_id, $meta_key, $meta_value, $unique = false) { |
| | 2019 | return add_metadata('taxonomy', $term_id, $meta_key, $meta_value, $unique); |
| | 2020 | } |
| | 2021 | |
| | 2022 | /** |
| | 2023 | * Remove metadata matching criteria from a term. |
| | 2024 | * |
| | 2025 | * You can match based on the key, or key and value. Removing based on key and |
| | 2026 | * value, will keep from removing duplicate metadata with the same key. It also |
| | 2027 | * allows removing all metadata matching key, if needed. |
| | 2028 | * |
| | 2029 | * @since 3.0 |
| | 2030 | * @uses delete_metadata |
| | 2031 | * @link http://codex.wordpress.org/Function_Reference/delete_term_meta |
| | 2032 | * |
| | 2033 | * @param int $term_id term ID |
| | 2034 | * @param string $meta_key Metadata name. |
| | 2035 | * @param mixed $meta_value Optional. Metadata value. |
| | 2036 | * @return bool False for failure. True for success. |
| | 2037 | */ |
| | 2038 | function delete_term_meta($term_id, $meta_key, $meta_value = '') { |
| | 2039 | return delete_metadata('taxonomy', $term_id, $meta_key, $meta_value); |
| | 2040 | } |
| | 2041 | |
| | 2042 | /** |
| | 2043 | * Retrieve term meta field for a term. |
| | 2044 | * |
| | 2045 | * @since 3.0 |
| | 2046 | * @uses get_metadata |
| | 2047 | * @link http://codex.wordpress.org/Function_Reference/get_term_meta |
| | 2048 | * |
| | 2049 | * @param int $term_id Term ID. |
| | 2050 | * @param string $key The meta key to retrieve. |
| | 2051 | * @param bool $single Whether to return a single value. |
| | 2052 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
| | 2053 | * is true. |
| | 2054 | */ |
| | 2055 | function get_term_meta($term_id, $key, $single = false) { |
| | 2056 | return get_metadata('taxonomy', $term_id, $key, $single); |
| | 2057 | } |
| | 2058 | |
| | 2059 | /** |
| | 2060 | * Update term meta field based on term ID. |
| | 2061 | * |
| | 2062 | * Use the $prev_value parameter to differentiate between meta fields with the |
| | 2063 | * same key and comment ID. |
| | 2064 | * |
| | 2065 | * If the meta field for the term does not exist, it will be added. |
| | 2066 | * |
| | 2067 | * @since 3.0 |
| | 2068 | * @uses update_metadata |
| | 2069 | * @link http://codex.wordpress.org/Function_Reference/update_term_meta |
| | 2070 | * |
| | 2071 | * @param int $term_id Term ID. |
| | 2072 | * @param string $key Metadata key. |
| | 2073 | * @param mixed $value Metadata value. |
| | 2074 | * @param mixed $prev_value Optional. Previous value to check before removing. |
| | 2075 | * @return bool False on failure, true if success. |
| | 2076 | */ |
| | 2077 | function update_term_meta($term_id, $meta_key, $meta_value, $prev_value = '') { |
| | 2078 | return update_metadata('taxonomy', $term_id, $meta_key, $meta_value, $prev_value); |
| | 2079 | } |
| | 2080 | |
| | 2081 | |
| | 2082 | // |