Attaching Metadata to a Taxonomy Item

I have a taxonomy of menus i.e. Coffee, Tea, Sandwiches, Cakes etc. I want to add more information ‘about’ the taxonomy such as an image that represents it alongside the other pieces of taxonomy information (slug,name,description).

Is this possible, how would you go about it?

Read More

Thanks, Stewart

Related posts

Leave a Reply

4 comments

  1. As Mamaduka said there is currently no (native) way of storing meta-data for taxonmies. There is talk of it. But it has stalled since its proving difficult to agree on how best to implement it.

    For large amounts of data you might not want to use the options table. Alternatively you can create your own taxonomy meta table. There are a couple plug-ins that currently do this:

    1. http://wordpress.org/extend/plugins/taxonomy-metadata/

    2. http://wordpress.org/extend/plugins/meta-for-taxonomies/

  2. Currently only way to store additional metadata for taxonomies is, adding them to WordPress options (wp_options table). Just for an images, you can remove kses filter from term’s description and insert image there.

    // Remove kses filter from term descriptions
    remove_filter( 'pre_term_description', 'wp_filter_kses' );
    

    About storing taxonomy metadata in options tables, you can see Brad Williams post: http://www.strangework.com/2010/07/01/how-to-save-taxonomy-meta-data-as-an-options-array-in-wordpress/

  3. I coded a class that stores metadata for taxonomy terms in the options table and working with it is fairly simple ex:

    //include the main class file
    require_once("Tax-meta-class/Tax-meta-class.php");
    // configure taxonomy custom fields
    $config = array(
       'id' => 'demo_tax_meta_box',                     // meta box id, unique per meta box
       'title' => 'Demo Meta Box',                      // meta box title
       'pages' => array('menus'),                       // taxonomy name, accept categories, post_tag and custom taxonomies
       'context' => 'normal',                           // where the meta box appear: normal (default), advanced, side; optional
       'fields' => array(),                             // list of meta fields (can be added by field arrays)
       'local_images' => false,                         // Use local or hosted images (meta box images for add/remove)
       'use_with_theme' => false                        //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
    );
    
    // Initiate your taxonomy custom fields
    $my_meta = new Tax_Meta_Class($config);
    
    // Add fields
    
    //text field
    $my_meta->addText('text_field_id',array('name'=> 'My tax Text '));
    //textarea field
    $my_meta->addTextarea('textarea_field_id',array('name'=> 'My tax Textarea '));
    //Image field
    $my_meta->addImage('image_field_id',array('name'=> 'My tax Image '));
    //Finish Taxonomy Extra fields Deceleration
    $my_meta->Finish();
    

    this will add a text field, textarea field and an image field.
    And getting the stored data is also very simple:

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

    currently the class supports:

    • Input
    • Textarea
    • Radio button
    • Checkbox
    • Select Dropdown
    • File Upload
    • Image Upload
    • WYSIWYG editor
    • Date Picker
    • Time Picker
    • Color Picker
    • Taxonomy List Dropdwon
    • Post list Dropdown
    • Repeater Field

    to read more about it look at : WordPress taxonomies extra fields the easy way