get_field_object
Get_field_object().
Description
This function will return an array containing all the field data for a given field_name
Parameters (3)
- 0. $field_key
- The field key.
- 1. $post_id — Optional. (constant) =>
false
- The post id.
- 2. $options — Optional. (array) =>
array()
- The options.
Usage
if ( !function_exists( 'get_field_object' ) ) { require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; } // The field key. $field_key = null; // The post id. $post_id = false; // The options. $options = array(); // NOTICE! Understand what this does before running. $result = get_field_object($field_key, $post_id, $options);
Defined (1)
The function is defined in the following location(s).
- /core/api.php
- function get_field_object( $field_key, $post_id = false, $options = array() ) {
- // make sure add-ons are included
- acf()->include_3rd_party();
- // filter post_id
- $post_id = apply_filters('acf/get_post_id', $post_id );
- $field = false;
- $orig_field_key = $field_key;
- // defaults for options
- $defaults = array(
- 'load_value' => true,
- 'format_value' => true,
- );
- $options = array_merge($defaults, $options);
- // is $field_name a name? pre 3.4.0
- if( substr($field_key, 0, 6) !== 'field_' )
- {
- // get field key
- $field_key = get_field_reference( $field_key, $post_id );
- }
- // get field
- if( substr($field_key, 0, 6) === 'field_' )
- {
- $field = apply_filters('acf/load_field', false, $field_key );
- }
- // validate field
- if( !$field )
- {
- // treat as text field
- $field = array(
- 'type' => 'text',
- 'name' => $orig_field_key,
- 'key' => 'field_' . $orig_field_key,
- );
- $field = apply_filters('acf/load_field', $field, $field['key'] );
- }
- // load value
- if( $options['load_value'] )
- {
- $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
- // format value
- if( $options['format_value'] )
- {
- $field['value'] = apply_filters('acf/format_value_for_api', $field['value'], $post_id, $field);
- }
- }
- return $field;
- }