• 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….

Viewing 1 replies (of 1 total)
  • I need someone to help me out on this please!!!

    I want to chain the select LOCATION to that of COUNTRY

    I mean if someone chose under country i.e Nigeria then under location ALL Nigeria states will be available to select.

    These are the codes:

    <label for=”country”>Country</label>

    <select id=”country” class=”show-menu-arrow selectpicker” name=”coun”>

    <option value=””>-</option>
    <option value=”nigeria”>Nigeria</otpion>
    <option value=”germany”>Germany</option>
    <?php

    $args=array(

    ‘post_type’ => ‘Property’,

    ‘posts_per_page’ => -1,

    );

    $i = 0;

    $locations = array();

    $wp_query=new WP_Query($args);

    while($wp_query->have_posts()):$wp_query->the_post();

    ?>

    <?php

    $value = get_post_meta(get_the_ID(),’_cmb_pro_country’, true);

    if (!in_array($value, $locations) && $value != ”) {

    $locations[$i] = $value;

    ?>

    <option value=”<?php echo get_post_meta(get_the_ID(),’_cmb_pro_country’, true);?>”><?php echo get_post_meta(get_the_ID(),’_cmb_pro_country’, true);?></option>

    <?php } ?>

    <?php $i++; ?>

    <?php endwhile;?>

    </select>

    <label for=”location”>Location</label>

    <select id=”location” class=”show-menu-arrow selectpicker” name=”location”>

    <option value=””>-</option>
    <option value=”lagos”>Lagos</option>
    <option value=”abuja”>Abuja</option>
    <?php

    $args=array(

    ‘post_type’ => ‘Property’,

    ‘posts_per_page’ => -1,

    );

    $i = 0;

    $locations = array();

    $wp_query=new WP_Query($args);

    while($wp_query->have_posts()):$wp_query->the_post();

    $value = get_post_meta(get_the_ID(),’_cmb_pro_location’, true);

    if (!in_array($value, $locations) && $value != ”) {

    $locations[$i] = $value;

    ?>

    <option value=”<?php echo get_post_meta(get_the_ID(),’_cmb_pro_location’, true);?>”><?php echo get_post_meta(get_the_ID(),’_cmb_pro_location’, true);?></option>

    <?php }

    $i++;

    endwhile;?>

    </select>

    I need help seriously.

Viewing 1 replies (of 1 total)
  • The topic ‘Show limited Categories wp backend’ is closed to new replies.