<?php
add_action('category_add_form_fields','extra_category_fields');
add_action ( 'edit_category_form_fields', 'extra_category_fields');
//add extra fields to category edit form callback function
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="extra1"><?php _e('Category Sidebar'); ?></label></th>
<td>
<select name="Cat_meta[sidebarpage]" id="Cat_meta[sidebarpage]">
<option value=""> </option>
<option value="organization" <?php if($cat_meta['sidebarpage']=="organization") echo "selected";?>>Organization Menu </option>
<option value="culturalbuilding" <?php if($cat_meta['sidebarpage']=="culturalbuilding") echo "selected";?>>Cultural building Menu</option>
</select>
<br />
<?php //echo $cat_meta['sidebarpage'];?>
<span class="description"><?php _e('Category Sidebar design'); ?></span>
</td>
</tr>
<?php
}
add_action('create_category','save_extra_category_fileds');
add_action ( 'edited_category', 'save_extra_category_fileds');
// save extra category extra fields callback function
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 );
}
}
Wednesday, July 24, 2013
How To Create Custom Taxonomies Fields In WordPress
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment