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
| Setting | Description |
|---|---|
| Field Key | Unique identifier. Lowercase letters and underscores only. |
| Label | Display label shown above the field. |
| Description | Optional helper text shown below the field. |
| Choices | List of radio options. Each has a value and a label. |
| Default Value | Optional pre-selected choice. |
| Layout | vertical 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