Unique result from two fields not working

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;
}

You are pulling the same field from the $_POST data for each item. $_POST[‘item_meta’] …
So, you would always get the same two for each. Not sure what this code is supposed to do, but
that is probably the problem…

Tell us what the real problem is that you are trying to solve by doing this. What is the high level overview of what you have going on?

Hi benanamen,
I’ve got further and got a new request at this link if you are able to have a look?

Sponsor our Newsletter | Privacy Policy | Terms of Service