get_field

Get_field().

Description

get_field( $field_key, (constant) $post_id = false, (bool) $format_value = true ); 

This function will return a custom field value for a specific field name/key + post_id. There is a 3rd parameter to turn on/off formating. This means that an Image field will not use its return option to format the value but return only what was saved in the database

Parameters (3)

0. $field_key
The field key.
1. $post_id — Optional. (constant) => false
The post id.
2. $format_value — Optional. (bool) => true
The format value.

Usage

  1. if ( !function_exists( 'get_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; 
  3.  
  4. // The field key. 
  5. $field_key = null; 
  6.  
  7. // The post id. 
  8. $post_id = false; 
  9.  
  10. // The format value. 
  11. $format_value = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_field($field_key, $post_id, $format_value); 
  15.  

Defined (1)

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

/core/api.php  
  1. function get_field( $field_key, $post_id = false, $format_value = true ) { 
  2.  
  3. // vars 
  4. $return = false; 
  5. $options = array( 
  6. 'load_value' => true,  
  7. 'format_value' => $format_value 
  8. ); 
  9.  
  10.  
  11. $field = get_field_object( $field_key, $post_id, $options); 
  12.  
  13.  
  14. if( is_array($field) ) 
  15. $return = $field['value']; 
  16.  
  17.  
  18. return $return; 
  19.