Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Example code showing how to hook WordPress to add fields to the taxonomny term edit screen.
* This example is meant to show how, not to be a drop in example.
* This example was written in response to this question:
* By:
* Mike Schinkel (
* This could easily become a plugin if it were fleshed out.
* A class with static methods was used to minimize the variables & functions added to the global namespace.
* wp_options was uses with one option be tax/term instead of via a serialize array because it aids in retrival
* if there get to be a large number of tax/terms types. A taxonomy/term meta would be the prefered but WordPress
* does not have one.
* This example is licensed GPLv2.
// These are helper functions you can use elsewhere to access this info
function get_taxonomy_term_type($taxonomy,$term_id) {
return get_option("_term_type_{$taxonomy}_{$term->term_id}");
function update_taxonomy_term_type($taxonomy,$term_id,$value) {
//This initializes the class.
//This should be called in your own code. This example uses two taxonomies: 'region' & 'opportunity'
class TaxonomyTermTypes {
//This initializes the hooks to allow saving of the
static function on_load() {
//This initializes the hooks to allow adding the dropdown to the form fields
static function register_taxonomy($taxonomy) {
if (!is_array($taxonomy))
$taxonomy = array($taxonomy);
foreach($taxonomy as $tax_name) {
// This displays the selections. Edit it to retrieve
static function add_form_fields($taxonomy) {
echo "Type " . self::get_select_html('text');
// This displays the selections. Edit it to retrieve your own terms however you retrieve them.
static function get_select_html($selected) {
$selected_attr = array('text'=>'','user'=>'','date'=>'','etc'=>'');
$selected_attr[$selected] = ' selected="selected"';
$html =<<<HTML
<select id="tag-type" name="tag-type">
<option value="text"{$selected_attr['text']}>Text</option>
<option value="user"{$selected_attr['user']}>User</option>
<option value="date"{$selected_attr['date']}>Date</option>
<option value="etc" {$selected_attr['etc']}>Etc.</option>
return $html;
// This a table row with the drop down for an edit screen
static function edit_form_fields($term, $taxonomy) {
$selected = get_option("_term_type_{$taxonomy}_{$term->term_id}");
$select = self::get_select_html($selected);
$html =<<<HTML
<tr class="form-field form-required">
<th scope="row" valign="top"><label for="tag-type">Type</label></th>
echo $html;
// These hooks are called after adding and editing to save $_POST['tag-term']
static function term_type_update($term_id, $tt_id, $taxonomy) {
if (isset($_POST['tag-type'])) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.