I'm able to add a field to the Categories, but only under Posts
- as in it's not showing up under my CPT categories, I want them to Only show up under my CPT Categories. Do I need a different hook?
Here's what I have so far:
/** 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="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
<td>
<input type="text" name="Cat_meta[bgc]" id="colorinput" size="3" style="width:20%;" value="<?php echo $cat_meta['bgc'] ? $cat_meta['bgc'] : '#fff'; ?>" class="my-color-field" />
<div id="colorpicker"></div><br />
<span class="description"><?php _e(''); ?></span>
<br />
</td>
</tr>
<?php
}
add_action ( 'category_add_form_fields', 'extra_category_fields');
/** Save Category Meta **/
function save_extra_category_fileds( $term_id ) {
if ( isset( $_POST['Cat_meta'] ) ) {
$t_id = $term_id;
$cat_meta = get_option( "category_$t_id");
$cat_keys = array_keys($_POST['Cat_meta']);
foreach ($cat_keys as $key){
if (isset($_POST['Cat_meta'][$key])){
$cat_meta[$key] = $_POST['Cat_meta'][$key];
}
}
//save the option array
update_option( "category_$t_id", $cat_meta );
}
}
add_action ( 'edited_category', 'save_extra_category_fileds');