3

Let's says I have a taxonomy called Types. I know I can have a singular name when registering the taxonomy... so I could just set the singular label to Type.

But is there a way to the same/similar to the actual terms inside Type?

Eg. Term / Plural / Singular Books -> Book Movies -> Movie

Will I need a custom field? Or is there a Wp way of doing this?

  • Personally I've hacked it using the desciption field. – bonger Nov 29 '15 at 18:33
  • Yeah.. I guess there's no way. I am already using the description field, but I can add a custom field. – gdaniel Nov 29 '15 at 18:35
2

In WordPress 4.4 we will be able to use the long waited term meta so you might use that to store the extra info for your terms.

The Term Meta API calls are:

Add term meta:

Function call:

add_term_meta( $term_id, $meta_key, $meta_value, $unique );

Description:

/**
 * 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:

Function call:

update_term_meta( $term_id, $meta_key, $meta_value, $prev_value );

Description:

/**
 * 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:

Function call:

delete_term_meta( $term_id, $meta_key, $meta_value )

Description:

/**
 * 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.
 */
  • Will 4.4 have an UI for it? – gdaniel Nov 29 '15 at 20:55
  • at least not like the custom fields UI for posts, afaik, but adding a custom term UI shouldn't be a major issue ;-) Here's the now closed trac ticket #10142 @gdaniel – birgire Nov 29 '15 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.