Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable a default value for checkbox groups
<?php
/**
* Enable a default value for checkbox groups.
* Your default value must be an array.
* You'll need to change the value of the $field_id to match your own Field ID
* @param $value The current value of the field
* @param $id The field ID in the format pewc_group_888_999
* @param $field The field object
* @param $posted The $_POST object
*/
function prefix_default_field_value( $value, $id, $field, $posted ) {
// Change this to the ID of the field you are setting a default for
$field_id = 999;
// Don't overwrite a value that's already there
if( $value ) {
return $value;
}
// Now look for our Field ID
if( $field_id == $field['field_id'] ) {
// You need to enter the default values here, copied exactly from your checkbox group options
$value = array(
'My first default option',
'My second default option'
);
}
return $value;
}
add_filter( 'pewc_default_field_value', 'prefix_default_field_value', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.