Term Meta

Add metas to terms in Wordpress

View the Project on GitHub Ayctor/ay-termmeta

Term Meta

Description

Add meta to terms in Wordpress

Usage

Activate the plugin and add some code to your functions.php

Use the function AyTermMeta::addMeta to add a meta to a term

/**
 * User function to add meta to terms.
 * @param string $term        Term name.
 * @param string $name        Meta name.
 * @param string $label       Form label.
 * @param string $type        Type of input.
 * @param string $description Description of the field.
 * @param array  $options     Options for select/radio/checkbox.
 */
  addMeta($term, $name, $label, $type = 'input', $description = '', $options = array()) {}

Basic example

Add an excerpt to a tag

AyTermMeta::addMeta('category', 'excerpt', 'Excerpt', 'input', 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.');

All term types

This code

AyTermMeta::addMeta('category', 'tag_excerpt', 'Excerpt', 'input', 'Excerpt description');

$radio_options = array(
  'male' => 'Male',
  'female' => 'Female',
  'unknown' => 'Unknown'
);
AyTermMeta::addMeta('category', 'gender', 'Gender', 'radio', 'Radio description', $radio_options);

$select_options = array(
  'africa' => 'Africa',
  'america' => 'america',
  'asia' => 'Asia',
  'europe' => 'Europe',
  'oceania' => 'Oceania'
);
AyTermMeta::addMeta('category', 'continent', 'Continent', 'select', 'Select description', $select_options);

$checkbox_options = array(
  'patatoes' => 'patatoes',
  'salad' => 'salad',
  'tomatoes' => 'tomatoes'
);
AyTermMeta::addMeta('category', 'food', 'Food', 'checkbox', 'Checkbox description', $checkbox_options);

AyTermMeta::addMeta('category', 'bio', 'Bio', 'textarea', 'Textarea description');

AyTermMeta::addMeta('category', 'myimage', 'My Image', 'file', 'Image description');

will generate these views

add form Add form

edit form Edit form

Advanced usage

You can use term_meta functions similar to post_meta function to add / update / get / delete metas

function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {}

function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {}

function get_term_meta( $term_id, $key = '', $single = false ) {}

function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {}

The documentation is the same as post_meta. You can find it here :

TODO