Skip to content

Radio

Radio buttons for selecting a single option from a visible list.

Radio Field

The Radio field displays a list of options as radio buttons, allowing exactly one selection. Use it when you want all options visible at once rather than hidden in a dropdown.


Field Settings

SettingDescription
Field KeyUnique identifier. Lowercase letters and underscores only.
LabelDisplay label shown above the field.
DescriptionOptional helper text shown below the field.
ChoicesList of radio options. Each has a value and a label.
Default ValueOptional pre-selected choice.
Layoutvertical or horizontal layout for the radio buttons.

Return Value

Returns a string — the value of the selected option. Returns an empty string if nothing is selected.


Usage

php

// Get the value
$size = onemeta_get_meta( get_the_ID(), 'field_key' );

// Display raw value
echo esc_html( $size );

// Use in a switch statement
switch ( $size ) {
    case 'small':
        $class = 'product-sm';
        break;
    case 'medium':
        $class = 'product-md';
        break;
    case 'large':
        $class = 'product-lg';
        break;
    default:
        $class = 'product-md';
}

echo '<div class="' . esc_attr( $class ) . '">';

Template Example

php

<?php $layout = onemeta_get_meta( get_the_ID(), 'content_layout' ); ?>

<div class="content content--<?php echo esc_attr( $layout ); ?>">
    <?php the_content(); ?>
</div>

Notes

  • Behaves identically to Select in terms of return value — both return a single string
  • Choose Radio over Select when you want all options visible without clicking a dropdown
  • The returned value is the choice value, not the label

On This Page