Button Group Field
The Button Group field displays choices as clickable buttons rather than a dropdown or radio list. It is functionally identical to the Radio field but provides a more prominent, visual selection UI.
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 button options. Each has a value and a label. |
| Default Value | Optional pre-selected choice. |
Return Value
Returns a string — the value of the selected button. Returns an empty string if nothing is selected.
Usage
php
// Get the value
$layout = onemeta_get_meta( get_the_ID(), 'field_key' );
// Use in template logic
if ( $layout === 'grid' ) {
get_template_part( 'template-parts/content', 'grid' );
} elseif ( $layout === 'list' ) {
get_template_part( 'template-parts/content', 'list' );
}
Template Example
php
<?php $style = onemeta_get_meta( get_the_ID(), 'hero_style' ); ?>
<section class="hero hero--<?php echo esc_attr( $style ); ?>">
<?php get_template_part( 'template-parts/hero', $style ); ?>
</section>
Notes
- Functionally identical to the Radio field — both return a single string value
- Choose Button Group for settings where a visual toggle-style UI improves the editing experience