Walker::get_number_of_root_elements()publicWP 2.7.0

Calculates the total number of root elements.

Method of the class: Walker{}

No Hooks.

Return

Int. Number of root elements.

Usage

$Walker = new Walker();
$Walker->get_number_of_root_elements( $elements );
$elements(array) (required)
Elements to list.

Changelog

Since 2.7.0 Introduced.

Walker::get_number_of_root_elements() code WP 6.1.1

public function get_number_of_root_elements( $elements ) {
	$num          = 0;
	$parent_field = $this->db_fields['parent'];

	foreach ( $elements as $e ) {
		if ( empty( $e->$parent_field ) ) {
			$num++;
		}
	}
	return $num;
}