9. Basic Field Types (Text, Number, Email, URL) | Field Forge - Custom Fields, Built for Speed
Download Log in

9. Basic Field Types (Text, Number, Email, URL)

Developer Guide

Field Forge supports 32 field types across 7 categories. This section covers the simple string and numeric fields.

Text

Stores a single-line string. Supports maxlength, placeholder, prepend, and append settings.

php
$value = get_field( 'headline' );
// Returns: 'Welcome to our site'

echo '<h1>' . esc_html( $value ) . '</h1>';

// With prepend/append configured in the admin (e.g., prepend = '$')
// The prepend/append is UI-only; the stored value is the raw input
$price = get_field( 'price_display' );
echo '<span class="price">$' . esc_html( $price ) . '</span>';

// Using text field as a CSS class
$layout = get_field( 'layout_class' );
echo '<div class="section ' . esc_attr( $layout ) . '">Content</div>';

Textarea

Multi-line text with configurable line-break handling.

php
// new_lines setting controls output:
// 'wpautop' wraps in <p> tags
// 'br' converts newlines to <br>
// '' returns raw text with n characters

$value = get_field( 'description' );
echo $value; // Already formatted based on new_lines setting

// When using raw mode (new_lines = ''), format manually
$raw = get_field( 'notes' );
echo '<pre>' . esc_html( $raw ) . '</pre>';

// Truncate textarea for card displays
$desc = get_field( 'description' );
$short = wp_trim_words( wp_strip_all_tags( $desc ), 20, '...' );
echo '<p class="card-excerpt">' . esc_html( $short ) . '</p>';

Number

Numeric value with optional min, max, and step.

php
$value = get_field( 'price' );
// Returns: float when the field has decimals (or the stored value contains a dot)
//          int otherwise. Examples: 29.99, 42, 0
// Type-casting in templates is no longer required, but defensive (float)/(int)
// casts are harmless if you prefer them.

echo '$' . number_format( $value, 2 );

// Use in calculations
$price    = get_field( 'price' );
$discount = get_field( 'discount_percent' );
$final    = $price * ( 1 - $discount / 100 );
echo '<p class="price">$' . number_format( $final, 2 ) . '</p>';

// Conditional rendering based on number
$stock = get_field( 'stock_quantity' );
if ( $stock > 0 ) {
    echo '<span class="in-stock">In Stock (' . $stock . ')</span>';
} else {
    echo '<span class="out-of-stock">Out of Stock</span>';
}

Range

Slider input that returns a numeric value.

php
$value = get_field( 'opacity' );
// Returns: int by default (e.g. 75), float if the slider step contains decimals.

echo '<div style="opacity: ' . esc_attr( $value / 100 ) . ';">Content</div>';

// Use range for grid columns
$columns = get_field( 'grid_columns' );
echo '<div class="grid" style="grid-template-columns: repeat(' . $columns . ', 1fr);">';

Email

Stores a validated email address string.

php
$email = get_field( 'contact_email' );
// Returns: '[email protected]'

echo '<a href="mailto:' . esc_attr( $email ) . '">' . esc_html( $email ) . '</a>';

// Obfuscate email for spam protection
$email = get_field( 'contact_email' );
echo '<a href="mailto:' . antispambot( $email ) . '">' . antispambot( $email ) . '</a>';

URL

Stores a validated URL string.

php
$url = get_field( 'website' );
// Returns: 'https://example.com'

echo '<a href="' . esc_url( $url ) . '" target="_blank" rel="noopener">Visit Site</a>';

// External link with icon
$url = get_field( 'documentation_url' );
if ( $url ) {
    echo '<a href="' . esc_url( $url ) . '" class="external-link" target="_blank" rel="noopener">';
    echo 'View Documentation <span class="icon-external"></span>';
    echo '</a>';
}

Password

Stores a plain-text string. Not encrypted at rest — use cautiously.

php
$pass = get_field( 'api_key' );
// Returns: raw string (stored as plain text)
// Use this type cautiously; not encrypted at rest
// Consider using the fieldforge/load_value filter to decrypt sensitive values

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs