Walker::get_number_of_root_elements() WordPress Method

The Walker::get_number_of_root_elements() function returns the number of top-level elements in the tree.

Walker::get_number_of_root_elements( array $elements ) #

Calculates the total number of root elements.


Parameters

$elements

(array)(Required)Elements to list.


Top ↑

Return

(int) Number of root elements.


Top ↑

More Information

Counts the number of top-level items (no children or descendants) in the provided array, and returns that count.


Top ↑

Source

File: wp-includes/class-wp-walker.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.