Skip Navigation

[Resolved] AJAX bug on cred_save_data function for multiple

This support ticket is created 6 years, 11 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by romanB-3 6 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#526312

Hello,

Beda helped me working out a solution to replace post's publication date when it's been edited in the cred form here : https://toolset.com/forums/topic/update-post-published-date-from-a-custom-date-field/#post-507723

I then tried to also apply this function to 3 other forms, and modified it like this :

// Remplacer la date de publication du post lors de la saisie dans le cred form
add_action('cred_save_data', 'always_prefix_data_action',10,2);
function always_prefix_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==1754 || 2361 || 2405 || 2429) 
    {
        //get post field value. This returns a TimeStamp if this is a Types Date Field
        $timestamp = get_post_meta($post_id, 'wpcf-date-de-la-depeche', true);
        $custom_date = gmdate("Y-m-d g:i:s", $timestamp);//convert timestamp to something like 2017-03-09 10:32:01 (Y/m/d g:i:s) for output and storage in the Database.
  
        // Update post post_date (publication date) with this date
        // Create $post_id object
        $my_post = array(
                'ID'           => $post_id,
                'post_date'    => $custom_date,
        );
  
        // Update the post into the database
        wp_update_post( $my_post );
    }
}

But now I noticed it's causing an AJAX bug as described here https://toolset.com/forums/topic/ajax-error-when-submitting-form/, where Noman noticed the bug is solved when the function is limited to only one form. So I understand the bug comes from this part of the code :

    // if a specific form
    if ($form_data['id']==1754 || 2361 || 2405 || 2429) 

Thank you.

#526379

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Roman,

Thank you for contacting our support forum.

Could you try using an If statement like this.

if ($form_data['id']==1754 || $form_data['id']==2361 || $form_data['id']==2405 || $form_data['id']==2429)

Thanks,
Shane

#526691

Thank you very much ! Just perfect.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.