wp_find_hierarchy_loop

Find hierarchy loops using a callback function that maps object IDs to parent IDs.

Description

(array) wp_find_hierarchy_loop( (callable) $callback, (int) $start, (int) $start_parent, (array) $callback_args = array() ); 

Returns (array)

IDs of all members of loop.

Parameters (4)

0. $callback (callable)
Function that accepts ( ID, $callback_args ) and outputs parent_ID.
1. $start (int)
The ID to start the loop check at.
2. $start_parent (int)
The parent_ID of $start to use instead of calling $callback( $start ). Use null to always use $callback
3. $callback_args — Optional. (array) => array()
Additional arguments to send to $callback.

Usage

  1. if ( !function_exists( 'wp_find_hierarchy_loop' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Function that accepts ( ID, $callback_args ) and outputs parent_ID. 
  5. $callback = null; 
  6.  
  7. // The ID to start the loop check at. 
  8. $start = -1; 
  9.  
  10. // The parent_ID of $start to use instead of calling $callback( $start ). 
  11. // Use null to always use $callback 
  12. $start_parent = -1; 
  13.  
  14. // Optional. Additional arguments to send to $callback. 
  15. $callback_args = array(); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = wp_find_hierarchy_loop($callback, $start, $start_parent, $callback_args); 
  19.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) { 
  2. $override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); 
  3.  
  4. if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) 
  5. return array(); 
  6.  
  7. return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );