Home › Forums › General Issues › hide item from post_object field › Reply To: hide item from post_object field
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.