Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$25
Advanced custom fields and gravity forms sync
I'm using two plugins advanced custom fields and gravity forms.
The advanced custom fields plugin is used for collecting data from wp-admin and gravity forms is used so that visitors to my site can submit data from the front-end.
All works really well and advanced custom fields post the data it collects back to the standard WordPress custom fields... however... when a user submits a gravity form from the front end the data is only added to the standard WordPress custom fields, but I need some way for this to be pushed back to the advanced custom fields too.
Hope that all makes sense. I've tried to come up with a solution to this myself but don't have any programming knowledge so am a bit lost.
Any help here is greatly appreciated.
This question has been answered.
Dale Williams | 08/29/11 at 10:38am
Edit
(5) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
08/29/11
10:47amUtkarsh Kukreti says:How have you created the field using "Advanced custom fields" plugin?
- 08/29/11 10:51am
Dale Williams says:Sorry was supposed to post a link, the plugin is by Elliot Condon, and can be found here: http://plugins.elliotcondon.com/advanced-custom-fields/
- 08/29/11 10:51am
-

Last edited:
08/29/11
11:32amDylan Kuhn says:I would hope that if you make "Field Name" in the Advanced Custom Fields plugin match "Custom Field Name" in gravity forms, both would use the same data.
-

Last edited:
08/29/11
11:37amHai Bui says:It's hard to solve because Advanced Custom Fields saves the data in custom db tables.
The best solution is replacing "Advanced Custom Fields" with custom code. You can follow this tutorial http://wefunction.com/2009/10/revisited-creating-custom-write-panels-in-wordpress/- 08/30/11 1:25am
Hai Bui says:Another solution is replacing "Advanced Custom Fields" with a similar plugin - "Magic Fields", you just have to use same custom field names.
- 08/30/11 1:25am
-

Last edited:
08/29/11
3:32pmSascha says:HI Dale,
I got frustrated with that problem too and decided to replace ACF with the 'More Fields' plugin. Try it out. It works great.
Hope you get there,
Sascha -

Last edited:
08/30/11
3:41pmJurre Hanema says:If you want to stick to ACF, you can try adding this code to your functions.php:
add_action('gform_pre_submission', 'wpq_register_added_meta_hook');
add_action('gform_post_submission', 'wpq_remove_added_meta_hook');
function wpq_register_added_meta_hook()
{
add_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_remove_added_meta_hook()
{
remove_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_added_post_meta($meta_id, $object_id, $meta_key, $meta_value)
{
global $wpdb;
if(!class_exists('Acf'))
return;
$query = $wpdb->prepare("SELECT id, save_as_cf FROM {$wpdb->prefix}acf_fields WHERE name = %s", $meta_key);
$acf_field = $wpdb->get_row($query);
if($acf_field)
{
$query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}acf_values (field_id, value, post_id) VALUES (%d, %s, %d)", $acf_field->id, $meta_value, $object_id);
$wpdb->query($query);
}
}
It's untested, but I have feeling it might "just work". The code I use to insert the data into ACF comes from a plugin I wrote a little while ago which had to import custom data from a CSV-file into ACF.- 08/30/11 4:57pm
Dale Williams says:Thanks for the reply, just gave this a go, but unfortunately it didn't work
- 08/30/11 5:13pm
Jurre Hanema says:I just tested the code and it should definitely work. Unfortunately, there is no easy way for me to see what goes wrong in your case.
Have you made sure that the "Field name" you have set in the ACF-plugin exactly matches the "Custom field name" you set in Gravity Forms? - 08/30/11 5:19pm
Dale Williams says:Yeah, all matching. Very strange. Which versions of ACF and Gravity Forms are you using? (I'm on 2.1.1 for ACF and 1.5.2.8 for Gravity Forms)
- 08/31/11 11:59am
Jurre Hanema says:Turns out I was using an older version of ACF. I modified the code a bit and tested it again of ACF 2.1.2. Try this updated code:
add_action('gform_pre_submission', 'wpq_register_added_meta_hook');
add_action('gform_post_submission', 'wpq_remove_added_meta_hook');
function wpq_register_added_meta_hook()
{
add_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_remove_added_meta_hook()
{
remove_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_added_post_meta($meta_id, $object_id, $meta_key, $meta_value)
{
global $wpdb;
if(!class_exists('Acf'))
return;
$query = $wpdb->prepare("SELECT id, save_as_cf FROM {$wpdb->prefix}acf_fields WHERE name = %s", $meta_key);
$acf_field = $wpdb->get_row($query);
if($acf_field)
{
$query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}acf_values (field_id, value, post_id) VALUES (%d, %d, %d)", $acf_field->id, $meta_id, $object_id);
$wpdb->query($query);
}
}
If this doesn't work, I'm stumped! - 08/31/11 2:33pm
Dale Williams says:Nope, still not working. Am I supposed to change anything in the code?
- 09/01/11 12:19pm
Dale Williams says:oddly it's working on one install, but as far as I can tell the config is exactly the same. Just wondering if the database upgrade in the new version of ACF would have changed anything?
I believe the one install it's working on was upgraded within WordPress and the ones which aren't working were fresh installs of ACF without any need for upgrading. - 09/01/11 5:00pm
Dale Williams says:Managed to find this in the error log, not sure if it helps in any way:
[01-Sep-2011 20:57:08] WordPress database error Unknown column 'save_as_cf' in 'field list' for query SELECT id, save_as_cf FROM wp_acf_fields WHERE name = 'guidewebsite' made by require, wp, WP->main, do_action_ref_array, call_user_func_array, RGForms->maybe_process_form, GFFormDisplay->process_form, GFFormDisplay->handle_submission, RGFormsModel->create_post, add_post_meta, add_metadata, do_action, call_user_func_array, wpq_added_post_meta - 09/02/11 2:21pm
Dale Williams says:After exchanging a few more messages with Jurre we now have this working. For anyone else who wants to do the same thing (with a clean install of ACF and WordPress) try the following code:
add_action('gform_pre_submission', 'wpq_register_added_meta_hook');
add_action('gform_post_submission', 'wpq_remove_added_meta_hook');
function wpq_register_added_meta_hook()
{
add_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_remove_added_meta_hook()
{
remove_action('added_post_meta', 'wpq_added_post_meta', 10, 4);
}
function wpq_added_post_meta($meta_id, $object_id, $meta_key, $meta_value)
{
global $wpdb;
if(!class_exists('Acf'))
return;
$query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}acf_fields WHERE name = %s", $meta_key);
$acf_field = $wpdb->get_row($query);
if($acf_field)
{
$query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}acf_values (field_id, value, post_id) VALUES (%d, %d, %d)", $acf_field->id, $meta_id, $object_id);
$wpdb->query($query);
}
}
The issue was that the ACF database is structured slightly differently on a clean install than it is on an updated (from a pervious) version.
- 08/30/11 4:57pm
This question has expired.
Dale Williams voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
