Walker::unset_children() WordPress Method

The Walker::unset_children() method is used to remove all of the child nodes of a given node from the walker's tree. This is useful if you want to exclude a certain branch of the tree from the walker's output.

Walker::unset_children( object $element, array $children_elements ) #

Unsets all the children for a given top level element.


Parameters

$element

(object)(Required)The top level element.

$children_elements

(array)(Required)The children elements.


Top ↑

Source

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

	public function unset_children( $element, &$children_elements ) {
		if ( ! $element || ! $children_elements ) {
			return;
		}

		$id_field = $this->db_fields['id'];
		$id       = $element->$id_field;

		if ( ! empty( $children_elements[ $id ] ) && is_array( $children_elements[ $id ] ) ) {
			foreach ( (array) $children_elements[ $id ] as $child ) {
				$this->unset_children( $child, $children_elements );
			}
		}

		unset( $children_elements[ $id ] );
	}


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.