Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter the default field value
<?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_set_field_value_by_url_param( $value, $id, $field, $posted ) {
// Change this to the ID of the field you are setting a default for
$field_id = 8018;
// Don't overwrite a value that's already there
if( isset( $_GET['my_param'] ) && $field_id == $field['field_id'] ) {
$value = esc_attr( $_GET['my_param'] );
}
return $value;
}
add_filter( 'pewc_default_field_value', 'prefix_set_field_value_by_url_param', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment