Closed adulovic closed 3 years ago
I didn't test it with ACF PRO yet. How are you saving the data? Using the regular wp-admin interface ?
users submitting data through forms on the frontend
Oh Right. At this moment the plugin only add a hook to the acf/save_post action.
I don't know if you are using a plugin like ACF Frontend or doing the implementation by yourself but it's probably using the update_field
function which will not trigger the acf/save_post action.
Am just doing cleanup duty after another programmer, seems like a vanilla install. Thanks for the tip, I'll look into that and report back if solved (in case anyone else has the same issue).
So, did a quick check and each form has its own submit function and they all use update_field
.
As an example, there is a function send_states($parameters) {...}
.
I tried adding the line add_action('acf/save_post', 'send_states');
before (and after) the function, but it still won't save into the custom table. I also tried them with priority 5 and priority 20, no luck...
Any suggestions on what else I could try?
I didn't test it but i'll do something like add a hook to the acf/update_value filter. That's triggered right before storing to database.
Then you can check for the table name and if its enabled or not in the acfict_table_name
and acfict_enabled
keys from $field parameter.
After that you can update the table using wpdb replace method for example:
<?php
add_filter('acf/update_value', function( $value, $post_id, $field, $original )
{
if ( $field[self::SETTINGS_ENABLED] && $field['name'] )
{
global $wpdb;
$column_name = acfict_sanitize_keyword( $field['name'] );
$column_value = apply_filters( 'acfict_sanitize_'.$field['type'], $value, $field );
$wpdb->replace( 'wp_acf_'. $field[ACF_FICT::SETTINGS_TABLE_NAME], [ $column_name => $column_value] );
}
return $value;
}, 10, 4);
Again, i didn't test it. I hope it can help you. Let me know if it works ;)
Tried your suggestion but it didn't help me much as the previous programmer didn't comment any of his code so it was a struggle to understand his logic. As I was in a hurry, I just created new forms and tables directly and the client is happy with that. Thanks for the help anyway
Hi,
WP 5.7.2 - fresh install PHP 7.4.1 MariaDB 10.4.10 ACF PRO 5.9.5
Custom Fields menu -> Add new:
1 | 0.0002 | 368064 | {main}( ) | ...\post.php:0 2 | 2.2539 | 4195264 | require( 'C:\Users\Viktor\Local Sites\hurghada\app\public\wp-admin\edit-form-advanced.php' ) | ...\post.php:206 3 | 2.3354 | 4367368 | do_meta_boxes( ) | ...\edit-form-advanced.php:688 4 | 2.3577 | 4458240 | ACF_FICT->render_metabox( ) | ...\template.php:1389 5 | 2.3650 | 4458368 | ( ) | ...\acf-fields-in-custom-table.php:108
WordPress v5.7.1 Advanced Custom Fields PRO v5.9.5 Advanced Forms v1.8.0 Sample table fields used: text, email, radio button, date time picker
Enabling ACF: Fields in Custom Tables creates a table with the prefix wpacf, But it does not insert any data sent by the forms. (Seems like the hook acf/update_field_group is working, but the acf/save_post isn't.)
Is this a know issue with the PRO version? Am I missing some important step? How can I debug?