Support

Account

Home Forums General Issues hide item from post_object field

Helping

hide item from post_object field

  • Hi i want to know how can i hide items from post object field once i select and save the post.

    eg: i’m going to create a new post and then i select post from post object relationship field, once i save the post and go to create new post. last selected item from post object field needs to be hidden or removed. and field need to contain only unselected or non related post object item that doesn’t belong to any post.

    Usecase : i’m creating a front end form and there is a select field(post_object) once user select prospect from that field and publish it. next time he create a new post that select field need to hide last post selected item. i hope this make sense.

    small example code is greatly helpful. thanks

  • There isn’t any easy way to do this and there isn’t any simple code I can post. There would be a lot of coding and testing involved to do something like this. All I can do is explain how it can be done.

    If I needed to do this I would use an option https://codex.wordpress.org/Options_API.

    I would create an acf/save_post action that runs before acf (priority < 10). I would look at the value of the relationship field, both the old value and the new value and update my option value as needed.

    I would then create an acf/fields/relationship/query filter https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/ that used the stored option value to prevent these posts from being selected.

    It gets even more complicated because you need to not prevent the selection of the related post that is already selected for the current post being edited if there is already a post selected.

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

The topic ‘hide item from post_object field’ is closed to new replies.