I have a custom Walker for a Advanced Search, that outputs the categories for multiple search by categories in checkbox. The Problem here is, that i use the get_category_children for the children Categories, but its old, and the new code is get_term_children, but when i replace it with it, then comes a error message, like
Warning: substr() expects parameter 1 to be string, object given in /..../search-fields.php on line 269
But the Search Functionality works.
The Code for the Walker Class is:
class Multiple_Walker_Category extends Walker
{
var $tree_type = 'category';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
function start_lvl(&$output, $depth, $args) {
$indent = str_repeat("\t", $depth);
$output .= "$indent<ul class='children'>\n";
}
function end_lvl(&$output, $depth, $args) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
function start_el($output, $category, $depth, $args)
{
extract($args);
$cat_name = esc_attr($category->name);
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
$cat_children = substr(**get_category_children**( $category->term_id, '', ', '), 0, -2 );
$output .= "<li><input type='checkbox' onchange='toggle( {$category->term_id}, Array( $cat_children, 999 ) )' class='cb-element' checked='checked' name='cat_{$category->term_id}' id='cat_{$category->term_id}' /> ";
$output .= "<label for='cat_{$category->term_id}'><span></span>$category->name</label>";
}
function end_el(&$output, $category, $depth, $args) {
$output .= "</li>\n";
}
}
How can i replace the old with the new term_children. Thanks everyone for the help.
function adv_form_cats($args = '')
{
$defaults = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_image' => '',
'exclude' => '',
'hierarchical' => true,
'title_li' => '',
'echo' => 0
);
$r = wp_parse_args( $args, $defaults );
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
}
if ( isset( $r['show_date'] ) ) {
$r['include_last_update_time'] = $r['show_date'];
}
extract( $r );
$categories = get_categories($r);
$output = '';
if ( $title_li && 'list' == $style )
$output = '<li class="categories">' . $r['title_li'] . '<ul>';
if ( empty($categories) ) {
if ( 'list' == $style )
$output .= '<li>' . __("No categories","WPL") . '</li>';
else
$output .= __("No categories","WPL");
} else {
global $wp_query;
if( !empty($show_option_all) )
if ('list' == $style )
$output .= "<li><input type='checkbox' id='checkAll' checked='checked' name='checkall' /> ";
$output .= "<label for='checkall'><span></span>".__('Check All', 'WPL').'</label>';
if ( is_category() )
$r['current_category'] = $wp_query->get_queried_object_id();
if ( $hierarchical )
$depth = 0; // Walk the full depth.
else
$depth = -1; // Flat.
$output .= walk_category_new_tree($categories, $depth, $r);
}
if ( $title_li && 'list' == $style )
$output .= '</ul></li>';
$output = apply_filters('wp_list_categories', $output);
return $output;
}
function walk_category_new_tree()
{
$walker = new Multiple_Walker_Category;
$args = func_get_args();
return call_user_func_array(array(&$walker, 'walk'), $args);
}