Hello,
Thanks for the feedback, and sorry for the late answer, I was kinda busy with the latest big patch lately.
You can do that using the acfe/form_validate_form
hook (see documentation), and check that the value of your Post Object doesn’t include the current post id (where the form is displayed)
add_action('acfe/form/validate_form/form=my-form', 'my_form_validation');
function my_form_validation($form){
// get current post id
// where the form is displayed
$post_id = $form['post_id'];
// get field input value (unformatted)
$my_post_object = get_field('my_post_object', false, false);
// check field value
if($my_post_object){
// if the Post Object allow multiple selection, use:
//
// if(is_array($my_post_object) && in_array($post_id, $my_post_object)){
// acfe_add_validation_error(...);
// }
//
// if the Post Object allow a single selection, use:
//
// if($my_post_object === $post_id){
// acfe_add_validation_error(...);
// }
//
// add validation error
// acfe_add_validation_error('my_post_object', 'Current page cannot be selected');
}
}
If you want to completely remove the current as being selectable in your Post Object, you can use the native acf/fields/post_object/query
hook (see documentation) to excldue a post.
The equivalent also exist for the ACF Relationship field in case you need it. See documentation here.
Hope it helps!
Have a nice day!
Regards.