I have a hierarchical category list, like:
A (Parent Category)
- B (Child Category)
- C (Child Category)
- D (Child Category)
B (Parent Category)
- E (Child Category)
- F (Child Category)
And i will, that if the Parent Category has Children Categorys, that then the Parent Category have the ID'S also of the Child Categorys, like
<input id="parent_1(ID)" class="checkbox" type="checkbox" name="parent_1(ID)" checked="checked" onchange="toggle( 1 (ID of the Parent Category), Array( 4, 3 (Both ID's of the Child Categorys), 999 ) )">
So that when Parent Category is check, the child Categorys also checked.
With the old function of Wordpress get_children_categories worked as expected, and java makes the rest with check the childrens by recognizing the id.
But my Problem is, that the function get_children_categories is depraceted and with the new function get_term_children its not work.
The old code looked so:
class Walker_Category extends Walker
{
var $tree_type = 'category';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
function start_lvl($output, $depth, $args) {
if ( 'list' != $args['style'] )
return $output;
$indent = str_repeat("\t", $depth);
$output .= "$indent<ul class='children'>\n";
return $output;
}
....................
function start_el($output, $category, $depth, $args)
{
extract($args);
$cat_name = esc_attr($category->name);
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
$children = substr( get_category_children( $category->term_id, '', ', '), 0, -2 );
li><input type='checkbox' onchange='toggle( {$category->term_id}, Array( $children, 999 ) )'
.................
But when i changed the code like:
$children = get_term_children( (int) $category->term_id, $category);
"<li><input type='checkbox' onchange='toggle( {$category->term_id}, Array( $children...
It gives only a 0 out. When i print_r than outputs arrays with the id's of the children categories, like:
$children = get_term_children( (int) $category->term_id, 'category');
$children = print_r( $children );
And the output is:
Array ( [0] => 3 [1] => 4 ) Array ( ) Array ( ) Array ( [0] => 6 ) Array ( )
Does anyone have any idea how I can release it? I'm already a few hours on it and come not forward with it. Or there may be another solution whereby the sub-categories are also checked. Thanks for the help ...