Description

Displays the value of the specified field. (this is the same as “echo get_field($field_name)”)

Parameters

<?php the_field($field_name, $post_id); ?>
  • $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

Usage

<?php 
 
/*
*  display a field value from the current post
*/
 
the_field( "text_field" ); 
 
/*
*  display a field value from another post
*/
 
the_field( "text_field", 123 ); 
 
/*
*  use the_field / get_field with conditional statements
*/
 
if( get_field( "text_field" ) ): ?>
    <p><?php the_field( "text_field" ); ?></p>
<?php endif;
/*
*  $post_id examples
*/
 
$post_id = null; // current post
$post_id = 1;
$post_id = "option";
$post_id = "options"; // same as above
$post_id = "category_2"; // save to a specific category
$post_id = "event_3"; // save to a specific taxonomy (this tax is called "event")
$post_id = "user_1"; // save to user (user id = 1)
 
?>