Skip Navigation

[Resolved] cred-save-data action

This support ticket is created 4 years, 9 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Shane 4 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1556297

Tell us what you are trying to do?
Trying to change post name based on data from custom fields upon save

I have two functions happening. The first, my_save_data_action, works fine.

The second, my_session_save_action, I am trying to save post name based on three fields. I am getting a series of numbers instead

function my_save_data_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==118){
                
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $custom_title = get_post_meta( $post_id, 'wpcf-account-name', true );
                
                //collect data and define new title
                $my_post = array(
                    'ID'               => $post_id,
                    'post_title'   => $custom_title,
                    'post_name' => $custom_title,
                    
                );
                
                // Update the post into the database
                wp_update_post( $my_post );
                
            }
        }
    add_action('cred_save_data', 'my_save_data_action2',10,2);
    
   function my_session_save_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==28){
                
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $first = get_post_meta( $post_id, 'wpcf-client-first-name', true );
				$last = get_post_meta( $post_id, 'wpcf-client-last-name', true );
				$date = get_post_meta( $post_id, 'wpcf-session-date', true );
				$custom_title = $date.' '.$last.' '.$first;
                
                //collect data and define new title
                $my_post = array(
				'ID' => $post_id,
				'post_title' => $custom_title,
				'post_name' => $custom_title,
                    
                );
                
                // Update the post into the database
                wp_update_post( $my_post );
                
            }
        }
    add_action('cred_save_data', 'my_session_save_action',20,2);
#1556659

Shane
Supporter

Languages: English (English )

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

Hi Mike,

Thank you for getting in touch.
Could you try changing the action priority to 10 ?

Example

    add_action('cred_save_data', 'my_session_save_action',10,2);

Thanks,
Shane