Support

Account

Home Forums Backend Issues (wp-admin) Is it possible to compare two fields inside a "acf/validate_value" filter?

Solved

Is it possible to compare two fields inside a "acf/validate_value" filter?

  • For example : one field is a number of beds I want, the other field “Hotel” has a post object select field (and this post has a meta data “beds_available”).

    Is it possible to validate the hotel field to compare the available beds with the “wanted_beds” field?

    That way It could return an invalid error saying “The hotel you want does not have this many beds available” or something like that.

  • Yes it is, but you need to access the value of the other field from the $_POST[‘acf’] array by its field key, example: $_POST['acf']['field_XXXXXXX']

  • Amazing ! As simple as that !
    Many thanks. I would have never thought about this and did not see this mentioned in the docs. That’d make a good example to make it simpler to understand this https://www.advancedcustomfields.com/resources/acf-validate_value/

    thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.