Support

Account

Home Forums General Issues Import data from CSV, sort and add the data into rows of a repeater field.

Solving

Import data from CSV, sort and add the data into rows of a repeater field.

  • I am creating something that will act like an attendance roster. The user will create a roster every 8 weeks. Each roster (custom post) will have a list of names+attendance for each of the 8 weeks. The user wants to add the data as a CSV in bulk when they create the roster for the first time, and then manually add data to it over the 8 weeks.

    I can create a field that let’s the user upload a CSV. How do I extract the data from this csv, sort it alphabetically and create repeater field rows for each name?

    The sorting only has to occur one time. But if possible, i’d like the repeater rows to be sorted and saved every time the post is saved.

  • Importing from ACF to repeater fields is something that can be difficult to achieve. There are some import plugins available that can do this. http://www.wpallimport.com/ is one of them.

    While it only took you one sentence to explain what you wanted, explaining how to achieve it would take significantly longer. If you really want to attempt this on your own, the best advice I can give you is to read all of the documentation available on ACF and to start digging around in the database and understand how ACF stores data.

  • I’ve been using wpallimport for a while, and it works well. But this site is going to be used by multiple people who aren’t very tech savvy, and I want them to be able to do everything from the post edit screen itself and in the front end version of the form.

    I’ve figured out how to populate a repeater field with data when you hit the save/publish button. But I want to understand a couple of things:

    1. How would you sort the repeater fields in the form?
    2. I think I can extract the data from the CSV uploaded to a File field, but how do I make sure that the data only gets imported into the repeater once? Is there a way to hide/disable a field in code?

    If you could direct me to any resources/posts that tackle any of the above problems, that would be very helpful.

    I will be happy to post the solution in this forum once i’ve figured out the whole thing.

  • I can’t say I’ve ever seen any documentation on this.

    I thought you were looking for information on everything from parsing the CSV to how to store the data.

    Sorting the repeater fields.

    I would create an acf/save_post hook that runs after ACF is done. I would then extract all of the data from the repeater field into and array and then insert it all back into the repeater field in the order that I wanted. I think this might be the only way.

    Making sure it was imported only once, basically you’d need to delete all of the data currently in the repeater before importing so that the import overwrites everything that’s already in there. Either that or you have to perform a check on every field and the content in the field to see if it already exists before insertion. Most import tools go with the “Delete everything and then reinsert” model.

    If you’ve been looking at storing data for acf repeater fields then you already know that it is a complex issue.

    Like I said above, I don’t know of much information on doing any of this, what I’ve figured out was basically by digging through the database and the acf code to figure out how it works.

  • This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.