0

So I'm able to add an extra field to my categories (A Color picker actually, to color code categories - pretty cool stuff if anybody is interested) but the extra field ONLY shows up under Posts. I have a CPT with its own category page and it doesn't show up there. Is there a way to only have the extra field show up under my CPT categories page? Do I need to hook into something different?

Here's what I'm doing now:

/** Add New Field To Category **/
function extra_category_fields( $tag ) {
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_$t_id" );
?>
<tr class="form-field">
    <th scope="row" valign="top"><label for="meta-color"><?php _e('Category Name Background Color'); ?></label></th>
    <td>
        <div id="colorpicker">
            <input type="text" name="cat_meta[catBG]" class="colorpicker" size="3" style="width:20%;" value="<?php echo (isset($cat_meta['catBG'])) ? $cat_meta['catBG'] : '#fff'; ?>" />
        </div>
            <br />
        <span class="description"><?php _e(''); ?></span>
            <br />
        </td>
</tr>
<?php
}
add_action ( 'category_add_form_fields', 'extra_category_fields');
add_action('category_edit_form_fields','extra_category_fields');
1
  • Have you created custom taxonomy for CPT? Sep 5, 2013 at 14:46

1 Answer 1

1

You can add the following hooks in your code to add it to event-category custom taxonomy.

add_action('event-category_edit_form_fields','extra_category_fields');  
add_action('event-category_add_form_fields','extra_category_fields'); 
6
  • I've seen this method before, like with managing post columns and such, does this work with most hooks? On that note, it doesn't seem to work - it removed them from Posts Categories but doesn't add them to my CPT Categories. Here's a pastebin with my CPT, Taxonomy, and Categories Fields - it seems to be spelled correctly.
    – Howdy_McGee
    Sep 5, 2013 at 14:50
  • These are the WordPress hooks. Sep 5, 2013 at 14:52
  • What's name of your CPT taxonomy? Sep 5, 2013 at 14:53
  • I added it all to a pastebin file Here
    – Howdy_McGee
    Sep 5, 2013 at 15:01
  • I have changed my code by referring your pastebin code. Test it now. Sep 5, 2013 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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