Output reference

Output values
by field type

This document provides output references for Custom Field Suite (CFS) and for features added by atshift Fields. The examples use field_name as a placeholder; replace it with your actual field name and escape all values according to their output context.

Text and values

Text and value fields

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Single-line text

String
<?php echo esc_html( CFS()->get( 'text' ) ); ?>

Textarea

String
<?php
$value = CFS()->get( 'textarea' );
echo nl2br( esc_html( $value ) );
?>

This example preserves line breaks when rendering plain text.

WYSIWYG editor

HTML string
<?php echo wp_kses_post( CFS()->get( 'wysiwyg' ) ); ?>

Phone number

String

Display the phone number only

<?php echo esc_html( CFS()->get( 'phone' ) ); ?>

Display as a phone link

<?php $phone = CFS()->get( 'phone' ); ?>
<a href="tel:<?php echo esc_attr( $phone ); ?>">
  <?php echo esc_html( $phone ); ?>
</a>

Email address

String

Display the email address only

<?php echo esc_html( antispambot( CFS()->get( 'email' ) ) ); ?>

Display as an email link

<?php $email = CFS()->get( 'email' ); ?>
<a href="mailto:<?php echo esc_attr( antispambot( $email ) ); ?>">
  <?php echo esc_html( antispambot( $email ) ); ?>
</a>

URL

String
<?php $url = CFS()->get( 'url' ); ?>
<a href="<?php echo esc_url( $url ); ?>">Visit link</a>

Number

String
<?php echo esc_html( CFS()->get( 'number' ) ); ?>

Date

String

Display the stored format

<?php echo esc_html( CFS()->get( 'date' ) ); ?>

Include the weekday

<?php
$date = CFS()->get( 'date' );
if ( $date ) {
  echo esc_html( wp_date( 'F j, Y (D)', strtotime( $date ) ) );
}
?>

wp_date() localizes the weekday for the WordPress site language. Adjust parsing to match the field's stored format.

Time

String

24-hour format

<?php
$time = CFS()->get( 'time' );
if ( $time ) {
  echo esc_html( wp_date( 'H:i', strtotime( $time ) ) );
}
?>

12-hour AM / PM format

<?php
$time = CFS()->get( 'time' );
if ( $time ) {
  echo esc_html( wp_date( 'g:i A', strtotime( $time ) ) );
}
?>

Color

String
<?php $color = sanitize_hex_color( CFS()->get( 'color' ) ); ?>
<span style="color:<?php echo esc_attr( $color ); ?>">Colored text</span>

Choices

Choice fields

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Select (dropdown menu)

Array
<?php foreach ( (array) CFS()->get( 'select' ) as $value ) : ?>
  <span><?php echo esc_html( $value ); ?></span>
<?php endforeach; ?>

The field returns an array even when configured for a single selection.

Checkbox

Array
<ul>
<?php foreach ( (array) CFS()->get( 'checkbox' ) as $value ) : ?>
  <li><?php echo esc_html( $value ); ?></li>
<?php endforeach; ?>
</ul>

Radio buttons

String
<?php echo esc_html( CFS()->get( 'radio' ) ); ?>

True / False (simple checkbox)

Boolean-like value
<?php if ( CFS()->get( 'true_false' ) ) : ?>
  <span>Enabled</span>
<?php endif; ?>

Conditional Group

Selected value string
<?php
$choice = CFS()->get( 'conditional_choice' );
?>

<?php if ( 'select1' === $choice ) : ?>
  <div>
    <p><?php echo esc_html( CFS()->get( 'field1' ) ); ?></p>
    <p><?php echo esc_html( CFS()->get( 'field2' ) ); ?></p>
  </div>

<?php elseif ( 'select2' === $choice ) : ?>
  <div>
    <p><?php echo esc_html( CFS()->get( 'field3' ) ); ?></p>
    <p><?php echo esc_html( CFS()->get( 'field4' ) ); ?></p>
  </div>
<?php endif; ?>

Retrieve the current selection using the Conditional Group's field name, then output the matching child fields. You can freely add HTML such as headings, images, and paragraphs between the PHP tags. Hidden branch values are retained, so do not output child fields without checking the selected value.

Links and media

Links and files

Replace the orange text with the field name you configured. Green text indicates escaping functions.

File (return URL)

URL string
<?php $file_url = CFS()->get( 'file' ); ?>
<a href="<?php echo esc_url( $file_url ); ?>">Download</a>

File (return ID)

Attachment ID
<?php
$attachment_id = (int) CFS()->get( 'file' );
echo wp_get_attachment_image( $attachment_id, 'large' );
?>

The returned value changes between a URL and an ID according to the field's Return Value setting.

Code view

HTML string
<?php
// Set the HTML tags and attributes that wp_kses() may output.
// true allows the specified attribute.
$allowed = array(
  'div' => array( 'class' => true ), // Allow div and its class attribute
  'span' => array( 'class' => true ), // Allow span and its class attribute
  'pre' => array(), // Allow pre without attributes
  'code' => array( 'class' => true ), // Allow code and its class attribute
  'button' => array( // Allow button with the attributes below
    'type' => true, 'class' => true, // type and class attributes
    'data-label' => true, 'data-copied' => true, // data attributes
  ),
);
echo wp_kses( CFS()->get( 'code_view' ), $allowed );
?>

Repeating values

Loops

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Loop (repeating fields)

Array of rows
<?php foreach ( (array) CFS()->get( 'items' ) as $row ) : ?>
  <article>
    <h3><?php echo esc_html( $row['title'] ?? '' ); ?></h3>
    <p><?php echo nl2br( esc_html( $row['description'] ?? '' ) ); ?></p>
  </article>
<?php endforeach; ?>

Each row is an array keyed by its subfield names. Escape every subfield according to its type.

Nested loop (repeating fields)

Array inside each row
<?php foreach ( (array) CFS()->get( 'sections' ) as $section ) : ?>
  <section>
    <h2><?php echo esc_html( $section['heading'] ?? '' ); ?></h2>
    <ul>
    <?php foreach ( (array) ( $section['items'] ?? array() ) as $item ) : ?>
      <li>
        <strong><?php echo esc_html( $item['title'] ?? '' ); ?></strong>
        <p><?php echo nl2br( esc_html( $item['description'] ?? '' ) ); ?></p>
      </li>
    <?php endforeach; ?>
    </ul>
  </section>
<?php endforeach; ?>

sections is the parent loop and items is the child loop. Read the child loop from the parent row array rather than calling CFS()->get() again.

WordPress native

WordPress-native data

Post categories

Terms
<?php
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) echo esc_html( $term->name );
}
?>

Post tags

Terms
<?php
$terms = get_the_terms( get_the_ID(), 'post_tag' );
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) echo esc_html( $term->name );
}
?>

Values from another post

Retrieve values outside the current post

Replace the orange text with the field name or post type you configured. Green text indicates escaping functions.

Retrieve by post ID

Post ID
<?php
$post_id = 123;
echo esc_html( CFS()->get( 'field_name', $post_id ) );
?>

Pass a post ID as the second argument of CFS()->get() to retrieve a field from any post, page, or custom post type, regardless of the currently displayed post.

Query and display one custom post

Custom post
<?php
$post_ids = get_posts( array(
  'post_type'      => 'news', // Specify post or a custom post type
  'posts_per_page' => 1,
  'post_status'    => 'publish',
  'orderby'        => 'date',
  'order'          => 'DESC',
  'fields'         => 'ids',
) );

if ( $post_ids ) :
  $post_id = (int) $post_ids[0];
?>
  <h4><?php echo esc_html(
    CFS()->get( 'text', $post_id )
  ); ?></h4>

  <p><?php echo nl2br( esc_html(
    CFS()->get( 'textarea', $post_id )
  ) ); ?></p>
<?php else : ?>
  <p>No data found.</p>
<?php endif; ?>

setup_postdata() and wp_reset_postdata() are not needed when you only retrieve CFS values by post ID. Use a standard WordPress loop when you also need template tags such as the post title.

Layout only

Layout-only fields

Tab, horizontal group, and accordion

These fields organize inputs in the WordPress admin. They do not store values themselves. Retrieve each field placed inside them by its own field name. Conditional Groups store their selected value; see the choice fields section above.