Documentation

get_field()

Description

Returns the value of the specified field.

This is a very versatile function. You can use it to store a value, echo a value and interact with a value. Please note the type of variable returned is relative to the field type. Eg: A repeater will return a multidimensional array.

Parameters

<?php $field = get_field($field_name, $post_id, $format_value); ?>
  • $field_name: the name of the field to be retrieved. eg “page_content” (required)
  • $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc
  • $format_value: whether or not to format the value loaded from the db. Defaults to true (not required).

Usage

<?php 

/*
*  get a field value from the current post
*/

$value = get_field( "text_field" ); 

/*
*  get a field value from another post
*/

$value = get_field( "text_field", 123 ); 

/*
*  use get_field with conditional statements
*/

$value = get_field( "text_field" );
if( $value )
{

}
else
{

}

Related Documents