Checkbox Field
The Checkbox field allows selecting multiple options simultaneously. Use it for feature lists, amenities, tags, skills, or any field where more than one option can be chosen at once.
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 checkable options. Each has a value and a label. |
| Default Value | Optional pre-checked choices. |
| Layout | vertical or horizontal layout for the checkboxes. |
Return Value
Returns an array of selected values. Returns an empty array [] if nothing is selected.
Always check
is_array()before looping — never assume the return is an array without checking.
Usage
php
// Get the value (returns array)
$features = onemeta_get_meta( get_the_ID(), 'field_key' );
// Loop through selected values
if ( is_array( $features ) && ! empty( $features ) ) {
echo '<ul>';
foreach ( $features as $feature ) {
echo '<li>' . esc_html( $feature ) . '</li>';
}
echo '</ul>';
}
// Check if a specific value is selected
if ( is_array( $features ) && in_array( 'wifi', $features, true ) ) {
echo '📶 WiFi Available';
}
Template Example
php
<?php $amenities = onemeta_get_meta( get_the_ID(), 'amenities' ); ?>
<?php if ( is_array( $amenities ) && ! empty( $amenities ) ) : ?>
<ul class="amenities-list">
<?php foreach ( $amenities as $amenity ) : ?>
<li class="amenity-item">
<?php echo esc_html( $amenity ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Notes
- Always use
is_array()before looping — the value may be empty or malformed - Use
in_array( $value, $array, true )with strict comparison to check for a specific selection - The returned values are the choice values, not the labels