Skip to content

Instantly share code, notes, and snippets.

@scribu
Created October 8, 2010 13:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scribu/616782 to your computer and use it in GitHub Desktop.
Save scribu/616782 to your computer and use it in GitHub Desktop.
Category Custom Fields
<?php
/*
Plugin Name: Category Custom Fields
Author: scribu
*/
class Category_Custom_Fields {
function init() {
add_action( 'load-edit-tags.php', array( __CLASS__, 'save' ) );
add_action( 'category_edit_form', array( __CLASS__, 'form' ) );
}
function save() {
if ( !isset( $_POST['action'] ) || 'editedtag' != @$_POST['action'] )
return;
$term_id = $_POST['tag_ID'];
$taxonomy = $_POST['taxonomy'];
// Check if the term exists
$term = get_term( $term_id, $taxonomy );
if ( is_null( $term ) || is_wp_error( $term ) )
return;
// Update the fields
update_term_meta( $term_id, 'field-1', $_POST[ 'field-1' ] );
update_term_meta( $term_id, 'field-2', $_POST[ 'field-2' ] );
}
function form( $term ) {
echo scbForms::table( array(
array(
'title' => 'Field 1',
'name' => 'field-1',
'type' => 'text',
'value' => get_term_meta( $term->term_id, 'field-1', true )
),
array(
'title' => 'Field 2',
'name' => 'field-2',
'type' => 'checkbox',
'checked' => get_term_meta( $term->term_id, 'field-2', true )
)
) );
}
}
Category_Custom_Fields::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment