0

im creating a lot of Categories with the same Name and different slugs, but im having problems identifying which is which in the admin panel, so i came up with the idea of inserting the slug besides the Name in the meta box...im using a taxonomy "portfolio-type"...anyway to do this i need to edit this file: wp-admin/includes/template.php in line 48:

Replace this:

esc_html( apply_filters('the_category', $category->name ))

With this:

esc_html( apply_filters('the_category', $category->name.' - '.$category->slug ))

anyway of doing this without editing the core file, lets say a function in my functions.php theme...and to add the slug only to the box containing taxonomy "portfolio-type"..

2

ok since i didn't have any response im posting the SOLUTION my self so it can be useful for others wanting to do the same:

add_filter('wp_terms_checklist_args', 'display_custom_checklist');
function display_custom_checklist( $args ){
    if ( $args['taxonomy'] == 'portfolio-type' )
    $args['walker'] = new my_custom_walk;
    return $args;
}
class my_custom_walk extends Walker {
    var $tree_type = 'category';
    var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this

    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent<ul class='children'>\n";
    }

    function end_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul>\n";
    }

    function start_el( &$output, $category, $depth, $args, $id = 0 ) {
        extract($args);
        if ( empty($taxonomy) )
            $taxonomy = 'category';

        if ( $taxonomy == 'category' )
            $name = 'post_category';
        else
            $name = 'tax_input['.$taxonomy.']';

        $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
        $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name.' - '.$category->slug )) . '</label>';
    }

    function end_el( &$output, $category, $depth = 0, $args = array() ) {
        $output .= "</li>\n";
    }
}
  • Seems a round about way , given that apply_filters( 'the_category', $category->name ) is there, but they do not give us anything else. That filter is USELESS really. it should be something like apply_filters( 'the_category', $category->name, $category ). Thanks for the help here mate. – Nathan Powell Sep 24 '15 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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