Title: Walker::unset_children
Published: April 25, 2014
Last modified: April 28, 2025

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#wp--skip-link--target)

Unsets all the children for a given top level element.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#parameters)󠁿

 `$element`objectrequired

The top level element.

`$children_elements`arrayrequired

The children elements.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#source)󠁿

    ```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 ] );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-walker.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-walker.php#L440)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-walker.php#L440-L455)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#related)󠁿

| Uses | Description | 
| [Walker::unset_children()](https://developer.wordpress.org/reference/classes/walker/unset_children/)`wp-includes/class-wp-walker.php` |

Unsets all the children for a given top level element.

  |

| Used by | Description | 
| [Walker::paged_walk()](https://developer.wordpress.org/reference/classes/walker/paged_walk/)`wp-includes/class-wp-walker.php` |

Produces a page of nested elements.

  | 
| [Walker::unset_children()](https://developer.wordpress.org/reference/classes/walker/unset_children/)`wp-includes/class-wp-walker.php` |

Unsets all the children for a given top level element.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/walker/unset_children/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwalker%2Funset_children%2F)
before being able to contribute a note or feedback.