I have a location field [539] and a date field [663] - latter receives combined result of two date fields and I need a unique result of the location field and combined date field. I’m using the code below but it doesnt appear to be working as testing results in positive eveytime when I’ve tried a negative test on a date I know is filled, I still get an appointment on that date?
add_filter('frm_validate_field_entry', 'two_fields_unique', 10, 2);
function two_fields_unique( $errors, $posted_field ) {
$first_field_id = 539; // change 125 to the id of the first field
$second_field_id = 663; // change 126 to the id of the second field
if ( $posted_field->id == $first_field_id ) {
$entry_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
$values_used = FrmDb::get_col( 'frm_item_metas',
array( 'item_id !' => $entry_id,
array( 'or' => 1,
array( 'field_id' => $first_field_id, 'meta_value' => $_POST['item_meta'][ $first_field_id ] ),
array( 'field_id' => $second_field_id, 'meta_value' => $_POST['item_meta'][ $second_field_id ] ),
)
), 'item_id', array( 'group_by' => 'item_id', 'having' => 'COUNT(*) > 1' )
);
if ( ! empty( $values_used ) ) {
$errors[ 'field'. $first_field_id ] = 'You have already selected that option';
$errors[ 'field'. $second_field_id ] = 'You have already selected that option';
}
}
return $errors;
}