Template functions

The functions you call in a theme (or plugin) to read and write Fieldstone values. All are available globally once the plugin is active.

Reading values

FunctionWhat it does
fstn_get_field( $name, $context, $format )Returns a field value, formatted by default. You escape the output.
fstn_the_field( $name, $context )Echoes the value already escaped with esc_html(). Best for plain text.
fstn_get_fields( $context )Returns every value for an object as a name => value array.

Writing values

FunctionWhat it does
fstn_update_field( $name, $value, $context )Sanitizes and stores a value.
fstn_delete_field( $name, $context )Deletes a value.

The $context argument

$context defaults to the current post in The Loop. It also accepts:

ValueReads from
123The post with that ID
'option'Site-wide values (a Pro Options page)
'user_5'User #5
'term_12'Term #12
a WP_Post / WP_User / WP_TermThat object
<?php
// Current post (inside The Loop)
$title = fstn_get_field( 'subtitle' );

// A specific post
$title = fstn_get_field( 'subtitle', 123 );

// Site-wide option, a user, a term
echo esc_html( fstn_get_field( 'company_tagline', 'option' ) );
echo esc_html( fstn_get_field( 'twitter', 'user_' . get_the_author_meta( 'ID' ) ) );
echo esc_html( fstn_get_field( 'icon', 'term_' . $term_id ) );
?>

Escaping — important

fstn_the_field() escapes for you with esc_html() — use it for plain text. fstn_get_field() returns the raw value so you can format it, which means you must escape the output with the right function for the context:

Reading many fields at once

<?php $f = fstn_get_fields(); ?>
<h2><?php echo esc_html( $f['full_name'] ?? '' ); ?></h2>

The shortcode

Print a value anywhere content is rendered — always escaped:

[fieldstone field="subtitle"]

Registering field groups in code

Prefer version control over the database UI? Register a group from a file with fstn_register_field_group() (or export any group as PHP from Fieldstone → Tools). See also Advanced → Local JSON, which syncs every definition to files automatically.

Front-end forms

Render a field group on the front of the site and accept the submission with fstn_form() — with validation, a honeypot and rate limiting. See Advanced → Front-end forms.