get_field_reference

Get_field_reference().

Description

get_field_reference( (string) $field_name, $post_id ); 

This function will find the $field_key that is related to the $field_name. This is know as the field value reference

Parameters (2)

0. $field_name (string)
The field name.
1. $post_id
The post id.

Usage

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

Defined (1)

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

/core/api.php  
  1. function get_field_reference( $field_name, $post_id ) { 
  2.  
  3. // cache 
  4. $found = false; 
  5. $cache = wp_cache_get( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, 'acf', false, $found ); 
  6.  
  7. if( $found ) 
  8. return $cache; 
  9.  
  10.  
  11. // vars 
  12. $return = ''; 
  13.  
  14.  
  15. // get field key 
  16. if( is_numeric($post_id) ) 
  17. $return = get_post_meta($post_id, '_' . $field_name, true);  
  18. elseif( strpos($post_id, 'user_') !== false ) 
  19. $temp_post_id = str_replace('user_', '', $post_id); 
  20. $return = get_user_meta($temp_post_id, '_' . $field_name, true);  
  21. else 
  22. $return = get_option('_' . $post_id . '_' . $field_name);  
  23.  
  24.  
  25. // set cache 
  26. wp_cache_set( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, $return, 'acf' ); 
  27.  
  28.  
  29. // return  
  30. return $return;