Working with repeating fields in Beaver Themer
Repeating fields are part of the Advanced Custom Fields Pro package but represent a very powerful fieldtype, used a lot in lists of repeating products or services. Beaver Themer doe not have yet native support for the ACF Pro fieldtypes, so a little workaround might help for the time being.
For our project fitnesskeuze.nl we were looking for a way on how to display two repeating fields, defined in the field group ‘sportscholen’. The two fields represent ‘groepslessen’ (group lessons) and ‘faciliteiten’ (facilities). Both fields have the freedom to add ‘subrecords’ depending on the amount of lessons and facilities each sportschool/fitness centre might have.
In both repeating fields we added just two subfields. ‘Naam’ stands for the name of the grouplessons and ‘omschrijving’ is the description of that lesson. So far so good in the back-end of our solution. Adding a CPT record ‘sportschool’ was initially done via the back-end as well, but the customer requested that a form could be used in the front-end for easy input (without user registration for the testperiod). The CPT record would have to appear as a draft for later approval and publication.
The solution
First we installed the brand new plugin Advanced Forms, a plugin for creating ACF forms in the front-end of your solution. Advanced Forms does support the ACF Pro repeating field, so that fitted our needs. The plugin creates its own (temporary) CPT record after each submit. We asked the developer to create a possibility to ‘convert’ this temporary CPT record to any CPT already created (in our case ‘sportscholen’). Developer Fabian Lindfors would have a look, but until now we will work with just a simple ‘post type converter’ called Post Type Switcher. We could have made a simple routine to do this, but for the test phase of our project, this solution worked fine.
Beaver Themer and Custom Content Shortcode
We do already use (with the customers permission) Beaver Themer to display both the archive page and the single page for the created CPT records. With the plug-in Custom Content Shortcode we ware able to display the two repeating fields. We hope that repeating field will become natively supported within Beaver Themer. The used plug-in works fine under WordPress 4.7.2, but no updates have been supplied in the last 9 months. The plugin does have some ‘special’ settings for ACF support and that worked fine for our setup.
We did just use the basic setup for displaying the two repeating fields, but with the plug-in any conditional could be created (nicely done). We did not test this in combination with the conditional possibilities offered with Beaver Themer yet.
Although not yet in it’s final (creative) layout, an example of the output just shows the easy integration in the single post layout created by Beaver Themer.
The next steps – suggestions welcome
This works for now, but we do seriously hope that Beaver Themer will add support for repeating fields soon, and that it will integrate within the Beaver Themer conditionals. We will replace the Post Type Switcher by a small routine in functions.php in the childtheme, if the developer of the Advanced Forms plug-in will not integrate this in his next version.
While people might fill in the front-end form, in the end we would like to give them the possibility to edit their content. Therefore a new user should be registered at the moment they create the CPT record. If that could be done, we would like to add an edit screen of the form in which the specific user can edit only his/her own CPT record. Any suggestion would be very welcome.