acf_get_child_field_from_parent_field

Acf_get_sub_field_from_parent_field().

Description

acf_get_child_field_from_parent_field( (string) $child_name, $parent ); 

This function is used by the get_sub_field_object to find a sub field within a parent field

Parameters (2)

0. $child_name (string)
The child name.
1. $parent
The parent.

Usage

  1. if ( !function_exists( 'acf_get_child_field_from_parent_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; 
  3.  
  4. // The child name. 
  5. $child_name = ''; 
  6.  
  7. // The parent. 
  8. $parent = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = acf_get_child_field_from_parent_field($child_name, $parent); 
  12.  

Defined (1)

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

/core/api.php  
  1. function acf_get_child_field_from_parent_field( $child_name, $parent ) 
  2. // vars 
  3. $return = false; 
  4.  
  5.  
  6. // find child 
  7. if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) ) 
  8. foreach( $parent['sub_fields'] as $child ) 
  9. if( $child['name'] == $child_name || $child['key'] == $child_name ) 
  10. $return = $child; 
  11. break; 
  12.  
  13. // perhaps child has grand children? 
  14. $grand_child = acf_get_child_field_from_parent_field( $child_name, $child ); 
  15. if( $grand_child ) 
  16. $return = $grand_child; 
  17. break; 
  18. elseif( isset($parent['layouts']) && is_array($parent['layouts']) ) 
  19. foreach( $parent['layouts'] as $layout ) 
  20. $child = acf_get_child_field_from_parent_field( $child_name, $layout ); 
  21. if( $child ) 
  22. $return = $child; 
  23. break; 
  24.  
  25.  
  26. // return 
  27. return $return; 
  28.