Title: ACF Relationship, Post Object Validation
Last modified: February 9, 2024

---

# ACF Relationship, Post Object Validation

 *  Resolved [mwhdesign](https://wordpress.org/support/users/mwhdesign/)
 * (@mwhdesign)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/acf-relationship-post-object-validation/)
 * I could use some help, I am using ACF Pro Relationship > Post Object for a frontend
   form which build/edits a post. I’d like to use AFC Extended Validation to prevent
   the user from selecting the same post, or itself. For example, BusinessXYZ will
   select a parter business from a list of all other businesses, but should not 
   be able to select themselves. I am new to the validation values and have not 
   had any luck so far. Any help would be greatly appreciated, thank you.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/acf-relationship-post-object-validation/#post-17727112)
 * 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](https://www.acf-extended.com/features/modules/forms/hooks#form-validation)),
   and check that the value of your Post Object doesn’t include the current post
   id (where the form is displayed)
 *     ```wp-block-code
       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](https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/))
   to excldue a post.
 * The equivalent also exist for the ACF Relationship field in case you need it.
   [See documentation here](https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/).
 * Hope it helps!
 * Have a nice day!
 * Regards.

Viewing 1 replies (of 1 total)

The topic ‘ACF Relationship, Post Object Validation’ is closed to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

## Tags

 * [$post object](https://wordpress.org/support/topic-tag/post-object/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 1 reply
 * 2 participants
 * Last reply from: [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/acf-relationship-post-object-validation/#post-17727112)
 * Status: resolved