Cybo Advanced Field EngineCyboweb Technologies · Documentation · v1.0.2

Select field

Purpose

A dropdown with one choice, or several when Allow Multiple is on.

Field type name

select

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.
Allow Multiple Let editors pick more than one option. The value becomes a list.
Allow Empty Show an empty option so editors can clear the selection.
Default Value Choice value(s) returned when nothing has been saved yet.
Placeholder Text of the empty option. (max 255 characters)
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

Depends on Return Format: the value ("red"), the label ("Red") or [ "value" => "red", "label" => "Red" ]. Multiple selects return a list of those. Nothing saved → null (or the default).

Example

cafe()->schema_manager()->create_field( $group_id, [
	'name'     => 'color',
	'type'     => 'select',
	'settings' => [
		'choices'       => [ 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue' ],
		'return_format' => 'label',
	],
] );

echo esc_html( cafe_get_field( 'color' ) ); // "Green"