Checkbox field
Purpose
Several choices from a list of checkboxes.
Field type name
checkbox
Settings
| Setting | Description |
|---|---|
| Instructions | Shown to editors below the field label. (max 2000 characters) |
| Choices | The options editors can pick. The value is stored; the label is shown. (required) |
| Return Format | What cafe_get_field() returns for a chosen option. |
| Default Value | Choice values returned when nothing has been saved yet. |
| Layout | How the options are arranged in the editor. |
| Translation | How the field behaves in other languages: translate, copy, copy_once or do_not_translate. Used on top-level fields when WPML is active. See WPML. |
| Width | Width on edit screens, to place fields side by side: 100 (full), 75, 66, 50, 33 or 25 (%). Phones always show full width. |
| Label per language | The label and instructions per language code while editing in that language, e.g. {"nl": {"label": "Prijs"}}. Set on the Translation tab when WPML is active. See WPML. |
PHP return value
A list, e.g. [ "option_a", "option_b" ] (or labels / [ value, label ] pairs per Return Format); null when nothing is saved.
Example
$features = cafe_get_field( 'features' ) ?? [];
if ( in_array( 'wifi', $features, true ) ) {
echo esc_html__( 'Free Wi-Fi', 'my-theme' );
}