I just resolved this issue! Woo hoo! The thing is that using var_dump($args)
shows a lot stuff like so:
object(stdClass)#152 (16) { ["menu"]=> object(WP_Term)#145 (10) { ["term_id"]=>
int(2) ["name"]=> string(9) "Main menu" ["slug"]=> string(9) "main-menu"
["term_group"]=> int(0) ["term_taxonomy_id"]=> int(2) ["taxonomy"]=> string(8)
"nav_menu" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(12)
["filter"]=> string(3) "raw" } ["container"]=> string(0) "" ["container_class"]=>
string(0) "" ["container_id"]=> string(0) "" ["menu_class"]=> string(4) "menu"
["menu_id"]=> string(0) "" ["echo"]=> bool(true) ["fallback_cb"]=> string(12)
"wp_page_menu" ["before"]=> string(0) "" ["after"]=> string(0) "" ["link_before"]=>
string(0) "" ["link_after"]=> string(0) "" ["items_wrap"]=> string(4) "%3$s"
["depth"]=> int(0) ["walker"]=> object(themeslug_walker_nav_menu)#151 (4) {
["tree_type"]=> array(3) { [0]=> string(9) "post_type" [1]=> string(8) "taxonomy"
[2]=> string(6) "custom" } ["db_fields"]=> array(2) { ["parent"]=> string(16)
"menu_item_parent" ["id"]=> string(5) "db_id" } ["max_pages"]=> int(1)
["has_children"]=> bool(true) } ["theme_location"]=> string(0) "" }
Searching through this dump you can clearly see ["has_children"]=> bool(true)
but the thing is that it isn’t part of $args
object! In fact it is part of object which is held under "walker"
value. This is more obvious when you indent a bit output like so:
object(stdClass)#152 (16) {
["menu"]=> object(WP_Term)#145 (10) {
["term_id"]=> int(2)
["name"]=> string(9) "Main menu"
["slug"]=> string(9) "main-menu"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(2)
["taxonomy"]=> string(8) "nav_menu"
["description"]=> string(0) ""
["parent"]=> int(0)
["count"]=> int(12)
["filter"]=> string(3) "raw"
}
["container"]=> string(0) ""
["container_class"]=> string(0) ""
["container_id"]=> string(0) ""
["menu_class"]=> string(4) "menu"
["menu_id"]=> string(0) ""
["echo"]=> bool(true)
["fallback_cb"]=> string(12) "wp_page_menu"
["before"]=> string(0) ""
["after"]=> string(0) ""
["link_before"]=> string(0) ""
["link_after"]=> string(0) ""
["items_wrap"]=> string(4) "%3$s"
["depth"]=> int(0)
["walker"]=> object(themeslug_walker_nav_menu)#151 (4) {
["tree_type"]=> array(3) {
[0]=> string(9) "post_type"
[1]=> string(8) "taxonomy"
[2]=> string(6) "custom"
}
["db_fields"]=> array(2) {
["parent"]=> string(16) "menu_item_parent"
["id"]=> string(5) "db_id"
}
["max_pages"]=> int(1)
["has_children"]=> bool(true)
}
["theme_location"]=> string(0) ""
}
Now you can clearly see that to access has_children
property you need to call this line:
$args->walker->has_children