WordPress.org

Make WordPress Core

Ticket #19851: category-template.slug_as_value.patch

File category-template.slug_as_value.patch, 1.6 KB (added by jackreichert, 9 years ago)

Patch for alternative solution to problem (details in comment)

  • wp-includes/category-template.php

     
    284284 *     'name' (string) - The name attribute value for select element.
    285285 *     'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
    286286 *     'class' (string) - The class attribute value for select element.
     287 *         'slug_as_value' (bool|int) - Uses category slug as option value instead of category ID.
    287288 *     'selected' (int) - Which category ID is selected.
    288289 *     'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
    289290 *
     
    308309                'name' => 'cat', 'id' => '',
    309310                'class' => 'postform', 'depth' => 0,
    310311                'tab_index' => 0, 'taxonomy' => 'category',
    311                 'hide_if_empty' => false
     312                'hide_if_empty' => false,
     313                'slug_as_value' => false
    312314        );
    313315
    314316        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
     
    946948         */
    947949        function start_el( &$output, $category, $depth, $args, $id = 0 ) {
    948950                $pad = str_repeat(' ', $depth * 3);
    949 
     951                $option_value = ( $args['slug_as_value'] == 'true' ) ? $category->slug : $category->term_id;   
    950952                $cat_name = apply_filters('list_cats', $category->name, $category);
    951                 $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
     953               
     954                $output .= "\t<option class=\"level-$depth\" value=\"".option_value."\"";
    952955                if ( $category->term_id == $args['selected'] )
    953956                        $output .= ' selected="selected"';
    954957                $output .= '>';