In the previous episode, we looked at the ways of bulk-handling repeating fields without shelling out the $ for the Repeater plugin. Again, not that I’m cheap because it’s not that much money. But I do think that making this work for users without a budget is worthwhile.
For most of these, it’s just a little bit of labor. There’s one instance where there were 10 repeated fields created by Magic Fields. My solution was to set these up as the ACF type “group,” with each of the 10 identical fields set up by duplicating the one above until I had 10.
In order to make it so that user interface wasn’t cluttered with a lot of field entry boxes that are seldom used I applied ACF’s conditional logic so that the second entry didn’t appear unless the first entry was populated; the third entry didn’t appear unless the two previous entries were populated; and so on.
But. For one of the fields a single post had 85 repetitions. Setting each of these manually was looking like a nightmare. I created 40 of them, saved the work so far, reloaded the page — and they were gone. As a matter of fact, for some reason, fields at the end were dropping off. A list of 20 would be cut down to 15. I’d add the final five again, and there would only be 19.
Then I realized that I could create a group, and duplicate the group. So with a click, 30 field entries could become 60. I’d have to tweak the internal conditional logic a little so the areas showed up at the right time (once group 1 was completed show group 2). Also, I could simplify my logic. I didn’t need every single field to be populated before the next one showed up; it could just be the previous one.
Another tweak I should do is show it if the current one is populated. Otherwise, if I have 15 images up and decide I want to de-populate image 11 — image 12, 13, 14 and 15 will disappear from the dashboard screen. Not good.
And populating the database and the template could be an issue. I would have to query each field group, and each image, with a naming convention for both that makes sense. Do-able but clunky.
Maybe there’s a better way
While looking through the ACF add-ons on wordpress.org I discovered a gallery module. Well doh! I should have looked for that originally. “ACF Photo Gallery Field” adds a new field type named, appropriately, “Photo Gallery.”
We’re going to want to see how this performs, and how it adds the images to the database.
It presents you with your media library, naturally, and you ctrl-click to group-select items. It adds a row to the postmeta table with the meta_key of whatever your field name is, and a meta_value that is a comma-separated list of image IDs.
Unfortunately, Magic Fields stores them as filenames. And Magic Fields image uploads don’t necessarily go into the uploads directory, certainly not organized by year/month the way a regular set of uploads is handled. I would really need to turn each of these uploaded images into a post of type “image,” maybe by using the upload-from-FTP plugin, and then reverse-querying the database to select the post_id where the correct image names is the value. This is getting crazy.
Where to go from here
I’ve spent so much time on this project, I could have rebuilt the entire thing from scratch. And I think I will. There are 185 posts to be managed. I can populate the custom fields the same way I did on the orchestra project, either by using the standard field set by MF or by creating duplicate fields, or simply by joining together text fields.
The images could be done programatically; but I can also just select them individually. It will be time consuming, but it won’t consume as much time as writing code that doesn’t break the site.
To make a long story short, I’m going to give up on doing a clean conversion of this site. Sorry.