Show limited Categories wp backend
-
Hello sir,
I want show limited categories in categories widget when I have add or edit post.
I have created one field show category with help of
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=”show_category”><?php _e(‘Show Category’); ?></label></th>
<td>
<input type=”checkbox” name=”cat_meta[showcategory]” id=”cat_meta[showcategory]” size=”3″ value=”1″ <?php checked( esc_attr( $cat_meta[‘showcategory’] ), 1 ); ?>>
<span class=”description”><?php _e(‘This Option Show Category on Category List’); ?></span>
</td>
</tr>
<?php
}
function add_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=”show_category”><?php _e(‘Show Category’); ?></label></th>
<td>
<input type=”checkbox” name=”cat_meta[showcategory]” id=”cat_meta[showcategory]” size=”3″ value=”1″ <?php checked( esc_attr( $cat_meta[‘showcategory’] ), 1 ); ?>>
<span class=”description”><?php _e(‘This Option Show Category on Category List’); ?></span>
</td>
</tr>
<?php
}
// 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 );
}
}
add_action ( ‘edited_category’, ‘save_extra_category_fileds’);
add_action( ‘category_edit_form_fields’, ‘extra_category_fields’, 10, 2 );
add_action( ‘category_add_form_fields’, ‘add_extra_category_fields’, 10, 2 );
add_action( ‘create_category’, ‘save_extra_category_fileds’, 10, 2 );these hook
Please help me…
sorry for my english….
- The topic ‘Show limited Categories wp backend’ is closed to new replies.