I’m trying to make my logic like this:
calling below code inside
function start_el( &$output, $item, $depth, $args ) {
$this->sub_items = 0; // declared variable as private $sub_items = 0 above inside class
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
foreach( $menu_items as $menu_item ) {
if( $menu_item->menu_item_parent == $item->ID ) {
$this->sub_items++;
}
}
}
}
I’m asuming that each time $this->sub_items returns calculated value for first level childs, and I can access it inside
function start_lvl( &$output, $depth ) {
echo $this->sub_items;
}
But unfortunately it doesn’t output correctly 🙁