A set of multiple checkboxes which stores as an array of the checked values.
This class extends Fieldmanager_Options
, which allows you to define options (values) via an array or via a dynamic Datasource, like posts, terms, or users.
-
Example 1: Basic List of Checkboxes
1234567891011add_action(
'fm_post_post'
,
function
() {
$fm
=
new
Fieldmanager_Checkboxes(
array
(
'name'
=>
'demo-field'
,
'options'
=>
array
(
'red'
=>
'Red'
,
'green'
=>
'Green'
,
'blue'
=>
'Blue'
,
),
) );
$fm
->add_meta_box(
'Checkboxes Demo'
,
array
(
'post'
) );
} );
-
Example 2: Datasource Example
This example will output a list of checkboxes with all users on the site. To provide the field with that data, it uses the User Datasource.
1234567add_action(
'fm_post_post'
,
function
() {
$fm
=
new
Fieldmanager_Checkboxes(
array
(
'name'
=>
'demo-field'
,
'datasource'
=>
new
Fieldmanager_Datasource_User,
) );
$fm
->add_meta_box(
'Checkboxes Demo'
,
array
(
'post'
) );
} );