Add custom fields in custom taxonomy meta box in wordpress-3.5.2

Roopendra picture Roopendra · Sep 26, 2013 · Viewed 13.4k times · Source

Unable to add custom fields in custom taxonomy meta box in wordpress-3.5.2.

I have checked solution in various blogs but Unable to solved this problem. I am using wordpress-3.5.2

What I am trying is :-

// A callback function to add a custom field to our "adtag" taxonomy
add_action( 'adtag_edit_form_fields', 'adtag_callback_function', 10, 2);

// A callback function to save our extra taxonomy field(s) 
add_action( 'edited_adtag', 'save_taxonomy_custom_fields', 10, 2 );

I have tried solution from below link:-

http://www.codehooligans.com/2010/07/07/custom-meta-for-new-taxonomies-in-wordpress-3-0/ http://sabramedia.com/blog/how-to-add-custom-fields-to-custom-taxonomies

http://www.wpbeginner.com/wp-tutorials/how-to-add-additional-custom-meta-fields-to-custom-taxonomies/

http://shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data

Answer

Marco Panichi picture Marco Panichi · Feb 24, 2015

Take a look at the Tax-meta-class developed to add extra fields to taxonomies: WordPress Taxonomies Extra Fields the easy way

1) Include the main class file

require_once("Tax-meta-class/Tax-meta-class.php");

2) Configure taxonomy custom fields

$config = array(
    'id' => 'demo_meta_box',
    'title' => 'Demo Meta Box',
    'pages' => array('category'),
    'context' => 'normal',
    'fields' => array(),
    'local_images' => false,
    'use_with_theme' => false
);

3) Initiate your taxonomy custom fields

$my_meta = new Tax_Meta_Class($config);

4) Add fields

//text field
$my_meta->addText('text_field_id',array('name'=> 'My Text '));
//textarea field
$my_meta->addTextarea('textarea_field_id',array('name'=> 'My Textarea '));

5) Finish Taxonomy Extra fields Deceleration [important!]

$my_meta->Finish();

6) Getting Saved data

$saved_data = get_tax_meta($term_id,'text_field_id');
echo $saved_data;