Hey Elliot – firstly, thanks so much for this amazing series of plugins. Not a day goes by that I don’t marvel at the ease and power that it adds to our development process!
I’m attempting to build a plugin that allows users to create lists of posts, sort of like wishlists. So the user will be able to create a new list, name it, and then save post IDs to those lists. The way I am implementing it is through a nested repeater field associated with the user.
On the post page, they can select from a dropdown of their existing lists, or they can type the name of a new one into a text box. Adding a new list is easy enough by passing an array into update_field, but how would I allow them to add a post ID into an already existing list?
Hope I explained that well enough, thanks!
Currently, the update_function will override the current value completely, which makes adding a row a bit of a hastle.
You will have to use the get_field function to load the entire repeater (parent repeater) and then add your new row to the nested repeater.
So, using the name of the list, you could get the parent repeater, loop through the rows and when you match the list name to that row’s list name value, you can then add to the corresponding causes.
Then, use the update_value function on the updated value.
Hey thanks Elliot, I’ve figured this out, however, now I am trying to figure out how to remove a nested repeater row. It seems simple enough using code like:
do_action('acf/delete_value', 101, 'causes_1_cause_id' );
Doing this removes the field from the database, however, it does not update the count field in the database and it does not decrease each subsequent row number by one. As you can see, running the code above results in the table looking like the screenshot below:
causes should have been changed to 2 and
(_)causes_2_cause_id should have been changed to
Is there a built-in function that will allow me to do this, or some direction on how to accomplish it?
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!
© 2019 Advanced Custom Fields. Subscribe