Hello,
Well, this looks like a custom validation implementation, and I don’t think this would be something that could be integrated within the UI, because there’s so many possible conditions/parameters.
You can add your own validation using the following ACF hook: https://www.advancedcustomfields.com/resources/acf-validate_value/
Here is an implementation example, which should work in your case:
In this example we’ll validate a field named my_number
and check if the value already exists in any other page
Post Type:
add_filter('acf/validate_value/name=my_number', 'my_acf_number_validation', 10, 4);
function my_acf_number_validation($valid, $value, $field, $input_name){
// Bail early if value is already invalid (example: required).
if($valid !== true)
return $valid;
// Setup search to check other pages
$args = array(
'post_type' => 'page',
'posts_per_page' => 1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'my_number',
'compare' => '=',
'value' => $value // input value
)
)
);
// Get current post ID
$post_id = acf_maybe_get_POST('post_ID');
// Exclude current post ID from the search
if(!empty($post_id)){
$args['post__not_in'] = array($post_id);
}
// Execute the search
$get_posts = get_posts($args);
// Search is empty. No other page is using this value
if(empty($get_posts))
return $valid;
// Search has found something. Return an error
$valid = 'This number is already used in an another page';
return $valid;
}
Hope it helps!
Have a nice day.
Regards.