Skip Navigation

[Resolved] Copy CRED save data to existing field that plugin generated

This thread is resolved. Here is a description of the problem and solution.

Problem:
Copy CRED save data to existing field that plugin generated using CRED hook cred_save_data not working

Solution:
There was a error with user code and the code is corrected with the following reply:

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/copy-cred-save-data-to-existing-field-that-plugin-generated/#post-620455

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.13 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by koheiY 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#620393

I have a product review site.
I want to copy CRED save data to existing field that plugin generated.

'user-review-point-input' is a generic field in CRED.
'review-31285-rating' is a custom field that SchemaPlugin (hidden link) generates.

What I want to is;
When my customer input and submit a rating value through 'user-review-point-input' field in CRED,
this post's 'review-31285-rating' field change to the same value.

This is a part of CRED Post Form. (Edit form)

<div class="form-group">
<label>Rating</label>
[cred_generic_field field='user-review-point-input' type='numeric' class='' urlparam='']
{
"required":1,
"validate_format":0,
"default":"3.0"
}
[/cred_generic_field]
</div>

I added this code in my function.php, but it doesn't work.

/* copy rating value from generic field in CRED to plugin's CF*/
add_action('cred_save_data', 'copy_generic_field_to_reviewplugins_field',10,2);
function copy_generic_field_to_reviewplugins_field($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==31390)
    {
        if (isset($_POST['user-review-point-input']))
        {
            update_post_meta($post_id, 'review-31285-rating', $_POST['user-review-point-input'] , true);
        }
    }
}

I read this forum.
https://toolset.com/forums/topic/cred-save-data-on-existing-field/

Would you give me some advice to my code?

#620455

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Could you please try to use following code and try to resolve your issue - I've removed the last argument "true" from update_post_meta function..

add_action('cred_save_data', 'copy_generic_field_to_reviewplugins_field',10,2);
function copy_generic_field_to_reviewplugins_field($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==31390)
    {
        if (isset($_POST['user-review-point-input']))
        {
            update_post_meta($post_id, 'review-31285-rating', $_POST['user-review-point-input'] );
        }
    }
}
#620509

Perfect! Thank you and have a good day:)