Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can I add some custom fields to specific taxonomy so when ever I call that taxonomy, custom fields attached to that taxonomy should also appear.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can hook into the edit form field action of that specific taxonomy.

If you look in /wp-admin/edit-tag-form.php there are hooks for every taxonomy. Starting at Line 69:

        if ( 'category' == $taxonomy )
        do_action('edit_category_form_fields', $tag);
    elseif ( 'link_category' == $taxonomy )
        do_action('edit_link_category_form_fields', $tag);
    else
        do_action('edit_tag_form_fields', $tag);

    do_action($taxonomy . '_edit_form_fields', $tag, $taxonomy);

So for a custom taxonomy, it would be $taxonomy_edit_form_fields with $taxonomy being the taxonomies name. So you would add the hook, within the function, add your form fields. Then you also need to hook into the 'edit_term' action and if your form fields aren't empty then save it as an option using update_option().

This won't allow you to just "call the taxonomy" and have them already attached to the object, but you can loop through your terms once you get them and get the option associated with that term very easily.

share|improve this answer

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.