Field Groups with ACF
-
Hi there, is it possible to use field groups with ACF?
I have Testimonials and FAQs I would like people to be able to upload when they submit a post that automatically get put into ACF Repeater fields for both. However, this seems to be the only field that doesn’t map when I submit a post. Is this possible? Thank you so much!
-
Hi @jeppner,
The plugin should support ACF as mentioned in this doc:
https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#custom-fieldsCould you please share a screenshot of what are the Field Types of “Testimonial” & “FAQ” fields configured in the ACF side, so that we could have a better idea?
Also please do share the form export, so that we could assist further.
Please check the following doc on how to export a form:
https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-exportIf you are concerned about any sensitive information in the form, then you can duplicate your form, remove any sensitive information, and then export it.
You can share the export file via Google Drive, Dropbox or any cloud services in the next reply.
Looking forward to your response.
Best Regards,
Nithin
Hi Nithin, thanks for the reply! Here is the form:
https://drive.google.com/file/d/1Jo9qIosrfshPbZvVVJ46T6NNzQqa9rjs/view?usp=sharing
Here is the FAQ config in ACF: https://i.gyazo.com/2aa16576b3c71a0124095c7a8559d04e.pngHere is the testimonial config: https://i.gyazo.com/0ac8a1f96bf6d816a0d92b8b7f504dc9.png
Appreciate your help!
Hi @jeppner,
Thanks for sharing the export which helps in giving a better idea. Please do note that by default the plugin doesn’t support repeaters inside the Field Group out of the box, this is something we’ll be looking to support down the roadmap.
However, I’m checking with our developer to see if there is any workaround that could be suggested to support such a worfklow.
Will keep you posted once we get further feedback asap.
Kind Regards,
Nithin
That would be awesome, thank you so much! Happy New Year!
Hi @jeppner,
I hope you are doing well today!
Our SLS (Second Line Support) team has provided the following code snippet which you can use as a mu-plugin.
<?php add_action( 'forminator_post_data_field_post_saved', 'wpmudev_repeater_format_acf_map', 10, 4 ); function wpmudev_repeater_format_acf_map( $post_id, $field, $data, $cls ) { $prepared_data = Forminator_CForm_Front_Action::$prepared_data; if ( 1338 != $prepared_data['form_id'] ) { // Please change the form ID. return; } $accordion_content = array(); $accordion_header = array(); $testimonial_text = array(); $testimonial_author = array(); $testimonial_role = array(); foreach ( $prepared_data as $key => $value ) { if ( false !== strpos( $key, 'textarea-3' ) ) { $accordion_content[] = $value; } if ( false !== strpos( $key, 'text-4' ) ) { $accordion_header[] = $value; } if ( false !== strpos( $key, 'textarea-2' ) ) { $testimonial_text[] = $value; } if ( false !== strpos( $key, 'text-1' ) ) { $testimonial_author[] = $value; } if ( false !== strpos( $key, 'text-2' ) ) { $testimonial_role[] = $value; } } if ( ! empty( $accordion_content ) ) { foreach ( $accordion_content as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_content', $v ); } update_post_meta( $post_id, 'accordion_repeater', count( $accordion_content ) ); } if ( ! empty( $accordion_header ) ) { foreach ( $accordion_header as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_header', $v ); } } if ( ! empty( $testimonial_text ) ) { foreach ( $testimonial_text as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_text', $v ); } update_post_meta( $post_id, 'testimonials', count( $testimonial_text ) ); } if ( ! empty( $testimonial_author ) ) { foreach ( $testimonial_author as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_author', $v ); } } if ( ! empty( $testimonial_role ) ) { foreach ( $testimonial_role as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_role', $v ); } } }
You need to change
1338
with your form’s ID.You can find more information below on how to use mu-plugins.
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
and
https://www.ads-software.com/support/article/must-use-plugins/Kind regards,
ZaferWow, thank you so much! That code worked perfectly! I really, really appreciate it.
We also decided to add author images to show, however, I’m unable to map the field accordingly when I try updating the code. I’m not sure if it’s because it’s an upload field that it needs to be handled a little differently? Did you have any ideas for that field? Thank you so, so much for your help!
Here’s how it’s being mapped on the posts: https://i.gyazo.com/c6e055190be8a5cc6dbbfcf8f61e2a04.png
<?php add_action( 'forminator_post_data_field_post_saved', 'wpmudev_repeater_format_acf_map', 10, 4 ); function wpmudev_repeater_format_acf_map( $post_id, $field, $data, $cls ) { $prepared_data = Forminator_CForm_Front_Action::$prepared_data; if ( 460 != $prepared_data['form_id'] ) { // Please change the form ID. return; } $accordion_content = array(); $accordion_header = array(); $testimonial_text = array(); $testimonial_author = array(); $testimonial_role = array(); $testimonial_image = array(); foreach ( $prepared_data as $key => $value ) { if ( false !== strpos( $key, 'textarea-3' ) ) { $accordion_content[] = $value; } if ( false !== strpos( $key, 'text-4' ) ) { $accordion_header[] = $value; } if ( false !== strpos( $key, 'textarea-2' ) ) { $testimonial_text[] = $value; } if ( false !== strpos( $key, 'text-1' ) ) { $testimonial_author[] = $value; } if ( false !== strpos( $key, 'text-2' ) ) { $testimonial_role[] = $value; } if ( false !== strpos( $key, 'upload-2' ) ) { $testimonial_image[] = $value; } } if ( ! empty( $accordion_content ) ) { foreach ( $accordion_content as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_content', $v ); } update_post_meta( $post_id, 'accordion_repeater', count( $accordion_content ) ); } if ( ! empty( $accordion_header ) ) { foreach ( $accordion_header as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_header', $v ); } } if ( ! empty( $testimonial_text ) ) { foreach ( $testimonial_text as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_text', $v ); } update_post_meta( $post_id, 'testimonials', count( $testimonial_text ) ); } if ( ! empty( $testimonial_author ) ) { foreach ( $testimonial_author as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_author', $v ); } } if ( ! empty( $testimonial_role ) ) { foreach ( $testimonial_role as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_role', $v ); } } if ( ! empty( $testimonial_image ) ) { foreach ( $testimonial_image as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_image', $v ); } } } ?>
Hi @jeppner,
I suppose you are using the “Image” field Type in ACF, I’m checking with our developer regarding this and will get back to you once we get further feedback.
Kind Regards,
Nithin
Hi @jeppner,
Please try this snippet:
<?php add_action( 'forminator_post_data_field_post_saved', 'wpmudev_repeater_format_acf_map', 10, 4 ); function wpmudev_repeater_format_acf_map( $post_id, $field, $data, $cls ) { $prepared_data = Forminator_CForm_Front_Action::$prepared_data; if ( 1367 != $prepared_data['form_id'] ) { // Please change the form ID. return; } $submitted_data = wp_list_pluck( Forminator_CForm_Front_Action::$info['field_data_array'], 'value', 'name' ); $accordion_content = array(); $accordion_header = array(); $testimonial_text = array(); $testimonial_author = array(); $testimonial_role = array(); $testimonial_image = array(); foreach ( $prepared_data as $key => $value ) { if ( false !== strpos( $key, 'textarea-3' ) ) { $accordion_content[] = $value; } if ( false !== strpos( $key, 'text-4' ) ) { $accordion_header[] = $value; } if ( false !== strpos( $key, 'textarea-2' ) ) { $testimonial_text[] = $value; } if ( false !== strpos( $key, 'text-1' ) ) { $testimonial_author[] = $value; } if ( false !== strpos( $key, 'text-2' ) ) { $testimonial_role[] = $value; } if ( false !== strpos( $key, 'upload-2' ) && ! empty( $submitted_data[$key]['file']['file_url'] ) ) { $testimonial_image[] = attachment_url_to_postid( $submitted_data[$key]['file']['file_url'] ); } } if ( ! empty( $accordion_content ) ) { foreach ( $accordion_content as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_content', $v ); } update_post_meta( $post_id, 'accordion_repeater', count( $accordion_content ) ); } if ( ! empty( $accordion_header ) ) { foreach ( $accordion_header as $k => $v ) { update_post_meta( $post_id, 'accordion_repeater_'.$k.'_accordion_header', $v ); } } if ( ! empty( $testimonial_text ) ) { foreach ( $testimonial_text as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_text', $v ); } update_post_meta( $post_id, 'testimonials', count( $testimonial_text ) ); } if ( ! empty( $testimonial_author ) ) { foreach ( $testimonial_author as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_author', $v ); } } if ( ! empty( $testimonial_role ) ) { foreach ( $testimonial_role as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_role', $v ); } } if ( ! empty( $testimonial_image ) ) { foreach ( $testimonial_image as $k => $v ) { update_post_meta( $post_id, 'testimonials_'.$k.'_testimonial_image', $v ); // testimonial_image should be changed to the acf field's meta key name } } }
In the above code please make sure to change
testimonial_image
to your ACF keyname for the image.Also make sure the form ID is correct in the code.
You can apply it as a mu-plugins as suggested before, please do check and see how that goes.
Kind Regards,
Nithin
Thank you Nithin, you and the team are amazing!!
- The topic ‘Field Groups with ACF’ is closed to new replies.