Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Saving extra fields that were added to a taxonomy. I want the most proper & efficient way of doing so. Where should I save the new fields?

2 possible solutions are to

1) Use the Wordpress options table as described here... Add Custom Fields to Custom Taxonomies. This is admittedly "not clean" and assumed not to be the correct answer.

// A callback function to save our extra taxonomy field(s)
function save_taxonomy_custom_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
    $t_id = $term_id;
    $term_meta = get_option( "taxonomy_term_$t_id" );
    $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ){
        if ( isset( $_POST['term_meta'][$key] ) ){
            $term_meta[$key] = $_POST['term_meta'][$key];
        }
    }
    //save the option array
    update_option( "taxonomy_term_$t_id", $term_meta );
}
}

2) Add a new table as described here Custom Taxonomies in Wordpress which follows the naming convention of 'wp_' + customtaxonomykey + 'meta'.

3) Some other option

share|improve this question

migrated from stackoverflow.com Jun 28 '12 at 1:51

1 Answer

up vote 1 down vote accepted

Option 2 is the cleanest method - which I've also used a number of times. Unfortunately, there is no default term_metadata table in WordPress yet. This post also covers the same approach, http://shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data

And of course, there's a plugin for that too :) http://wordpress.org/extend/plugins/taxonomy-metadata/

share|improve this answer
Great tutorial link. So easy! Thank you. (of course I wanted to roll my own as plug ins are too easy of a solution!) – Christopher Ickes Jun 28 '12 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.