我有一个用于高级搜索的自定义助行器,它通过复选框中的类别输出多个搜索的类别。这里的问题是,我将get\\u category\\u children用于children类别,但它是旧的,而新代码是get\\u term\\u children,但当我将其替换为它时,会出现一条错误消息,如
Warning: substr() expects parameter 1 to be string, object given in /..../search-fields.php on line 269
但搜索功能是有效的。
Walker类的代码为:
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";
}
}
我怎样才能用新的term\\u children替换旧的。谢谢大家的帮助。
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);
}