get_fields
Get_fields().
Description
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
if ( !function_exists( 'get_fields' ) ) { require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; } // The post id. $post_id = false; // The format value. $format_value = true; // NOTICE! Understand what this does before running. $result = get_fields($post_id, $format_value);
Defined (1)
The function is defined in the following location(s).
- /core/api.php
- function get_fields( $post_id = false, $format_value = true ) {
- // vars
- $options = array(
- 'load_value' => true,
- 'format_value' => $format_value
- );
- $fields = get_field_objects( $post_id, $options );
- if( is_array($fields) )
- {
- foreach( $fields as $k => $field )
- {
- $fields[ $k ] = $field['value'];
- }
- }
- return $fields;
- }