get_fields

Get_fields().

Description

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

This function will return an array containing all the custom field values for a specific post_id. The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the values.

Parameters (2)

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

Usage

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

Defined (1)

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

/core/api.php  
  1. function get_fields( $post_id = false, $format_value = true ) { 
  2.  
  3. // vars 
  4. $options = array( 
  5. 'load_value' => true,  
  6. 'format_value' => $format_value 
  7. ); 
  8.  
  9.  
  10. $fields = get_field_objects( $post_id, $options ); 
  11.  
  12. if( is_array($fields) ) 
  13. foreach( $fields as $k => $field ) 
  14. $fields[ $k ] = $field['value']; 
  15.  
  16. return $fields;