Add meta to terms in Wordpress
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()) {}
AyTermMeta::addMeta('category', 'excerpt', 'Excerpt', 'input', 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.');
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
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 :
Add textarea input typeAdd image input type- Show the meta in the table listing
- Add term thumbnail