How to change value for 'options' and 'select' in wp_dropdown_categories?

I am currently using this code to display only the child terms of the current category being viewed -

<?php

//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_dropdown_categories
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 2,
    'title_li' => '',
        'show_option_all' => All,
        'hide_if_empty' => true
    );
 wp_dropdown_categories( $args );
?>

I need to be able to add values and classes to the 's and the opening . How can I modify the above code to do so?

Im not sure but I think Im getting close. -

<?php
function get_terms_dropdown($taxonomies, $args){
//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 2,
    'title_li' => '',
        'show_option_all' => All,
        'hide_if_empty' => true
    );
    $output ="<select name='".$term_slug."'><option selected='".$selected."' value='".$emptyvalue."'>Select a Category</option>'";

    foreach($current_term as $term){
        $output .="<option name='".$term_slug."' value='".$link."'>".$term_name."</option>";
    }
    $output .="</select>";
return $output;
}
echo get_terms_dropdown($taxonomies, $args);

?>

The problem is the drop down is not showing any categories/terms, what am I missing?

Answers


Ok yet I answered another one of my own questions. I was able to create the drop down filter that retrieves the child terms of the current taxonomy page being viewed. For anyone interested in the solution, here it is ---

First I had to create in my functions.php file a walker class --

class SH_Walker_TaxonomyDropdown extends Walker_CategoryDropdown{

    function start_el(&$output, $category, $depth, $args) {
        $pad = str_repeat('&nbsp;', $depth * 2);
        $cat_name = apply_filters('list_cats', $category->name, $category);

        if( !isset($args['value']) ){
            $args['value'] = ( $category->taxonomy != 'category' ? 'slug' : 'id' );
        }

        $value = ($args['value']=='slug' ? $category->slug : $category->term_id );

        $output .= "\t<option class=\"level-$depth\" data-filter-value=\".".$value."\"";
        if ( $value === (string) $args['selected'] ){ 
            $output .= ' selected="selected"';
        }
        $output .= '>';
        $output .= $pad.$cat_name;
        if ( $args['show_count'] )
            $output .= '&nbsp;&nbsp;('. $category->count .')';

        $output .= "</option>\n";
}
 }

Then I placed this code in my sidebar --

<?php

//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_dropdown_categories
 $args = array(
    'walker'=> new SH_Walker_TaxonomyDropdown(),
    'value'=>'slug',
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 2,
    'title_li' => '',
    'id' => 'filter-select',
    'class' => 'filter option-set',
        'show_option_all' => All,
        'hide_if_empty' => true
    );
 wp_dropdown_categories( $args );
?>

Need Your Help

How to make TreeViewItem non collapsible

wpf xaml treeview treeviewitem

I am working on a WPF project and I have a TreeView using HierarchicalDataTemplates. I have been able to establish some different levels of nodes. Everything is going well so far.

Primefaces printer print div

printing jsf-2 primefaces

I want to print one div with primefaces printer (primefaces 3.2 with myfaces 2.0).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.