只需设置name
复选框标记中的属性,格式如下:favourite_colors[]
. 以下代码派生自this thread.
add_settings_field(
\'favourite-colors\',
\'Select your favourite colour\',
\'favourite_colors_checkbox_callback\',
\'my-settings\'
);
function favourite_colors_checkbox_callback() {
$options = get_option( \'favourite_colors\' );
$html = \'<input type="checkbox" id="red" name="favourite_colors[red]" value="1"\' . checked( 1, $options[\'red\'], false ) . \'/>\';
$html .= \'<label for="red">Red</label><br />\';
$html = \'<input type="checkbox" id="yellow" name="favourite_colors[yellow]" value="1"\' . checked( 1, $options[\'yellow\'], false ) . \'/>\';
$html .= \'<label for="yellow">Yellow</label>\';
echo $html;
}