We are using a Relationship field in our WP site to connect events with members (custom post types) and we’d like to know if there is the possibility to add all members from the list to the event (see screenshot). We want to have an “Add all” button i.e. once you click on it, all items from the left list will be added to the second list (on the right). Is there a hook that could manage this please?
Another easier method is to update the list on save. This means that the entries will be added once you saved the contents and reloaded the editor page. You can use the true/false so the user can choose if they want to add all of the entries and then use the update_field() function in the acf/save_post action hook to add them.
I hope this helps 🙂
I agree that the first option is not really achievable, but I’d like to elaborate on the second one, if that’s all right.
1) We add the button in HTML
3) We’d somehow indicate to the user that All or None are selected.
4) When user saves the post we use the acf/save_post hook to read our “SelectAll” variable and depending on its value we update the field accordingly. (Add or remove all guest members).
5) Page reloads and correct result appears in the relation field.
Can you please confirm my understanding is correct?
Thank you 🙂
Your understanding is correct, but you can simplify it like this:
1. Create a true/false field type that says “Select all members on save?” and place it after the relationship field. You can also hide the relationship field if the true/false field is selected by using the conditional logic.
2. When a user saves the post, you can use the “acf/save_post” hook to check if the true/false field is selected. If it is, then update the relationship field by using the update_field() function.
3. The page is reloaded automatically when the user clicks the save button, so the relationship fields should show the correct result after that.
I hope this makes sense 🙂
I’m afraid that isn’t possible. If you want it, you can submit a feature request by opening a new ticket so the request can be passed directly to the plugin author. Hope he will consider it in the future.
You can open the new ticket here: https://support.advancedcustomfields.com/new-ticket.
You must be logged in to reply to this topic.
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!