Fields
Types
Number

Number Field

A numeric input field with optional min/max constraints and step increments.

Basic Usage

$stack->field('quantity', [
    'type' => 'number',
    'label' => 'Quantity',
    'default' => 1,
]);

Properties

PropertyTypeDefaultDescription
typestring-Required. Must be 'number'
labelstring-Field label displayed to users
descriptionstring''Help text below the field
defaultint|float0Default value
attributesarray[]Additional attributes
conditionsarray[]Conditional display rules

Attributes

AttributeTypeDefaultDescription
minint|float-Minimum allowed value
maxint|float-Maximum allowed value
stepint|float1Increment step value
suffixstring''Unit suffix (e.g., 'px', '%')
prefixstring''Unit prefix (e.g., '$')
placeholderstring''Placeholder text

Examples

Container Width

$stack->field('container_width', [
    'type' => 'number',
    'label' => 'Container Width',
    'default' => 1200,
    'attributes' => [
        'min' => 960,
        'max' => 1920,
        'step' => 10,
        'suffix' => 'px',
    ],
]);

Percentage Value

$stack->field('content_width', [
    'type' => 'number',
    'label' => 'Content Width',
    'default' => 70,
    'attributes' => [
        'min' => 50,
        'max' => 100,
        'step' => 5,
        'suffix' => '%',
    ],
]);

Price Field

$stack->field('price', [
    'type' => 'number',
    'label' => 'Price',
    'default' => 0,
    'attributes' => [
        'min' => 0,
        'step' => 0.01,
        'prefix' => '$',
    ],
]);

Header Height

$stack->field('header_height', [
    'type' => 'number',
    'label' => 'Header Height',
    'default' => 80,
    'attributes' => [
        'min' => 60,
        'max' => 150,
        'step' => 5,
        'suffix' => 'px',
    ],
]);

Font Size

$stack->field('font_size', [
    'type' => 'number',
    'label' => 'Font Size',
    'default' => 16,
    'attributes' => [
        'min' => 12,
        'max' => 24,
        'step' => 1,
        'suffix' => 'px',
    ],
]);

With Conditional Display

$stack->field('cache_duration', [
    'type' => 'number',
    'label' => 'Cache Duration (days)',
    'default' => 7,
    'attributes' => [
        'min' => 1,
        'max' => 365,
        'step' => 1,
    ],
    'conditions' => [
        ['field' => 'enable_cache', 'operator' => '==', 'value' => true],
    ],
]);

Retrieving Value

// For options
$width = my_option('container_width', 1200);
 
// Ensure integer
$width = (int) my_option('container_width', 1200);
 
// For post meta
$quantity = (int) get_post_meta($post_id, 'quantity', true);

Output Example

// CSS output
.container {
    max-width: <?php echo esc_attr(my_option('container_width', 1200)); ?>px;
}
 
// Inline style
<div style="height: <?php echo esc_attr(my_option('header_height', 80)); ?>px;">

Related Fields

  • range - For visual slider input
  • text - For text input