9. Types de Champs de Base (Texte, Nombre, Email, URL) | Field Forge - Champs personnalisés, conçus pour la vitesse
Télécharger Se connecter

9. Types de Champs de Base (Texte, Nombre, Email, URL)

Field Forge prend en charge 32 types de champs répartis sur 7 catégories. Cette section couvre les champs de chaîne et numériques simples.

Texte

Stocke une chaîne sur une seule ligne. Prend en charge les paramètres maxlength, placeholder, prepend, et append.

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>';

Zone de Texte

Texte multi-lignes avec gestion des sauts de ligne configurable.

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>';

Nombre

Valeur numérique avec min, max et pas optionnels.

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>';
}

Plage

Entrée de curseur qui retourne une valeur numérique.

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

Stocke une chaîne d’adresse email validée.

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

Stocke une chaîne d’URL validée.

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>';
}

Mot de Passe

Stocke une chaîne en texte clair. Non chiffré au repos — à utiliser avec précaution.

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

Assistant IA Forge En ligne

Bonjour ! Je suis l'assistant IA Field Forge. Posez-moi n'importe quelle question sur le plugin — configuration, fonctionnalités, dépannage ou développement.

À l'instant
Propulsé par Forge IA · Parcourir la documentation