Skip to content

Button Group

A visual button-based selector for single-choice selection with a more prominent UI.

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

SettingDescription
Field KeyUnique identifier. Lowercase letters and underscores only.
LabelDisplay label shown above the field.
DescriptionOptional helper text shown below the field.
ChoicesList of button options. Each has a value and a label.
Default ValueOptional 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

On This Page