Home › Forums › General Issues › Custom ACF datagrids with multiple inputs
I’m in the process of making a custom ACF field for one of my own projects.
In the panel markup for this field I have some table (three in fact) with numerical inputs in its cells. I’m running some js calculations in wpadmin when an user enters data in the cells inputs. Think of it as a sort of spreadsheets with predefined operations.
Now, I’m still learning how to store and save data with a custom ACF. My problem here is that I have several fields in my custom field, there are literally dozens of numerical input I need to save. I was thinking, maybe I could use hidden fields to store data in the form of arrays or serialized data. Ideally I wouldn’t like the idea of using only one field to store everything. For example, in the frontend I really need only some totals from one of the tables row to be used, whereas in the backend I still need to store values from all other inputs involved in the calculations to retain the data when an admin opens again the post from backend. Also, if I had to store everything in one single field as array/serialized data, I think it wouldn’t be efficient to query everything if I need only a specific row in the frontend.
So the question is: using ACF and the ACF template kit, can I save my data consistently to 4-5 different meta fields while still using ACF framework?
If not, I’ll consider to switch back to write my own regular custom meta field functions if this can’t be accomplished optimally with ACF.
ps – if this can be done, but I’d be not able to use get_field() later it’d be still ok (or alternatively use get_field() to retrieve from frontend the values from the row I’m mostly interested to), as long as data saving is consistent. I can’t achieve this with regular repeater/flexible fields, as I need to run some calculations across cells – and visually it wouldn’t be friendly due to the amount of columns required;
Thanks for the question. The ACF framework is not built to save multiple values to the DB for each field, only one.
The repeater field can handle multiple values because it adds an extra level of logic. This is why it is a premium add-on.
I would advise that you think about using a custom DB table to save all the data to. That way, you have full controll over the SQL.
Your field file has a function called update_value. This is where you can do custom SQL.
Also, the load_value function will allow you to read in the data through custom SQL.
Hope that helps.
The topic ‘Custom ACF datagrids with multiple inputs’ is closed to new replies.
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!
We demoed ACF 6.1 Beta during the most recent session of ACF Chat Fridays, highlighting the new ability to regenerate and clear labels, setting the Admin Menu Parent as a slug, and more. Catch the video replay in our latest summary. https://t.co/rHEpPVas64 pic.twitter.com/hB1XKTexXi— Advanced Custom Fields (@wp_acf) March 23, 2023
© 2023 Advanced Custom Fields.