Hi,
I need to update a custom metadata if a field value change. How can I do that?
I cannot use the register user action because I cannot update the user role ( I have several ones). Any ideas? I can retrieve the value of the user metadata using shortcode.
Assuming that "field value change" means the user or admin updates the entry via the front (or back) end, you can use the frm_after_update_entry hook.
add_action('frm_after_update_entry', 'update_used_passes', 10, 2);
function update_used_passes($entry_id, $form_id){
if ( $form_id == 35 ) {
$userid = $_POST['item_meta'][867];// 867 is the ID of the userID field
$used_passes = $_POST['item_meta'][875];// 875 is the ID of the used passes field
$pass_status = $_POST['item_meta'][970];// 970 is the ID of the pass status field
if ( $userid && $pass_status=="Approved") {
// Get the current value.
$count = (int) get_field('passes_used', $userid);
// Increase it.
$count++;
update_field('passes_used', $count, $userid);
}
}}
it doesn't work
Turn on WordPress debugging and use error_log to output information to tell you where it's going wrong. First verify that the function is being called and then output values along the way to see what's happening.
Please login or Register to submit your answer