get_field_object()

Overview

Returns the settings (array) of a specific field.

The field’s value will also be loaded unless otherwise specified.

Parameters

get_field_object($selector, [$post_id], [$format_value], [$load_value]);
  • $selector (string) (Required) The field name or field key
  • $post_id (mixed) (Optional) The post ID where the value is saved. Defaults to the current post
  • $format_value (bool) (Optional) Whether to apply formatting logic. Defaults to true
  • $load_value (bool) (Optional) Whether to load the field’s value. Defaults to true

Return

This function will return an array looking something like the following. Please note that each field contains unique settings.

array(
	'ID'				=> 0,
	'key'				=> '',
	'label'				=> '',
	'name'				=> '',
	'prefix'			=> '',
	'type'				=> 'text',
	'value'				=> null,
	'menu_order'		=> 0,
	'instructions'		=> '',
	'required'			=> 0,
	'id'				=> '',
	'class'				=> '',
	'conditional_logic'	=> 0,
	'parent'			=> 0,
	'wrapper'			=> array(
		'width'				=> '',
		'class'				=> '',
		'id'				=> ''
	)
);

Usage

<?php 

/*
*  Get a field object and display it with it's value
*/

$field_name = "text_field";
$field = get_field_object($field_name);

echo $field['label'] . ': ' . $field['value'];

/*
*  Get a field object and display it with it's value (using the field key and the value fron another post)
*/

$field_key = "field_5039a99716d1d";
$post_id = 123;
$field = get_field_object($field_key, $post_id);

echo $field['label'] . ': ' . $field['value'];

/*
*  Get a field object and create a select form element
*/

$field_key = "field_5039a99716d1d";
$field = get_field_object($field_key);

if( $field )
{
	echo '<select name="' . $field['key'] . '">';
		foreach( $field['choices'] as $k => $v )
		{
			echo '<option value="' . $k . '">' . $v . '</option>';
		}
	echo '</select>';
}

?>