Compatible API reference

Original CFS-compatible
API reference

atshift Fields preserves the main theme APIs from the original Custom Field Suite. Existing calls such as CFS()->get() can generally continue to be used as they are.

Values

Retrieve values

CFS()->get()

Compatible API

Retrieves a stored value by field name. Pass a post ID as the second argument to retrieve from another post. Omit the field name to retrieve the CFS field values for the post as an array.

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

echo esc_html( CFS()->get( 'field_name', 123 ) );

$fields = CFS()->get();
?>

Retrieval and output are separate steps. Escape for the output context with functions such as esc_html(), esc_url(), and wp_kses_post().

format option

api / input / raw

The third argument can specify the value format. For normal theme output, use the default api format.

<?php
$value = CFS()->get( 'field_name', get_the_ID(), array(
  'format' => 'raw',
) );
?>

raw is useful when you need the unformatted stored value. For most templates, api is easier to work with.

Field metadata

Retrieve field information

get_field_info()

Compatible API

Retrieves field settings from the field groups matching the current post or a specified post.

<?php
$info = CFS()->get_field_info( 'field_name' );

echo esc_html( $info['label'] ?? '' );
?>

All field information

Array

Omit the field name to retrieve all available field information.

<?php
$fields = CFS()->get_field_info();

foreach ( $fields as $field_name => $field ) {
  echo esc_html( $field['label'] ?? $field_name );
}
?>

Reverse relationship

Reverse relationship lookup

get_reverse_related()

Compatible API

Returns post IDs that reference a given post through a relationship field.

<?php
$post_ids = CFS()->get_reverse_related( get_the_ID(), array(
  'field_name'  => 'related_posts',
  'post_type'   => 'post',
  'post_status' => 'publish',
) );

foreach ( $post_ids as $post_id ) {
  echo esc_html( get_the_title( $post_id ) );
}
?>

atshift Fields hardens the reverse relationship query by sanitizing input values and preparing SQL clauses.

Save

Save values

save()

Compatible API

Saves CFS field values. Pass an ID to update an existing post, or provide post data such as post_type and post_status to create a new post.

<?php
$post_id = CFS()->save(
  array(
    'field_name' => 'Value to save',
  ),
  array(
    'ID' => get_the_ID(),
  )
);
?>

Create a new post and save fields

<?php
$post_id = CFS()->save(
  array(
    'field_name' => 'Value to save',
  ),
  array(
    'post_type'   => 'post',
    'post_status' => 'draft',
    'post_title'  => 'Draft title',
  )
);
?>

When saving from the front end, always combine this with a nonce, authentication, current_user_can() capability checks, and input validation.

Find fields

Find field definitions

find_fields()

Compatible API

Retrieves field definitions matching the provided conditions. You can filter by field group ID or field type.

<?php
$fields = CFS()->find_fields( array(
  'group_id' => 123,
) );
?>

Find by field type

Array
<?php
$relationship_fields = CFS()->find_fields( array(
  'field_type' => 'relationship',
) );
?>

Front-end forms

Render forms

form()

atshift Fields support

Renders a field group as a front-end form. atshift Fields keeps the compatible API while adding stronger server-side validation, submitted-value preservation, and inline error display.

<?php
echo CFS()->form( array(
  'post_id'          => false,
  'field_groups'     => array( 123 ),
  'post_type'        => 'post',
  'post_status'      => 'draft',
  'submit_label'     => 'Save',
  'confirmation_url' => home_url( '/thanks/' ),
) );
?>

See the implementation examples for creating new posts and editing existing posts.

Compatibility notes

Compatibility notes

Preserved

CFS 2.6.7-compatible
  • Main API methods called through CFS().
  • Existing field groups, post metadata, and theme output using CFS()->get().
  • Core data structures for loops, relationships, and field metadata.

Review during migration

Site-specific checks
  • Fields that depended on original CFS Add-ons.
  • Fields added by atshift Fields if you later return to the original plugin.
  • Escaping for fields that contain HTML.
  • Capabilities and validation when saving from the front end.