Skip Navigation

[Resolved] cred-save-data

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

Problem:
The user would like to build an automatic title with a formatted date.

Solution:
Use PHP date function to format the date.

Relevant Documentation:
https://www.php.net/manual/en/function.date.php

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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikeF-8 4 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#1565453

Hi, this is a continuation of https://toolset.com/forums/topic/cred-save-data-action/

Apologies for the delay.

I made the suggested change in priority, but getting the same response. I've included the first action ("account name") which works. The problem is "session name", the second action, which I'm getting post titles such as "1585267200"

Thanks in advances.

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',10,2);
#1565519

Hello and thank you for contacting the Toolset support.

Toolset stores the date field to database as a timestamp, that's why your field is having numbers. You will need to format it into a human-readable date with the PHP date function, like date("F j Y", $date).
Check this post which is a little similar to your case https://toolset.com/forums/topic/append-date-field-to-title/
hidden link

I hope this helps. Let me know if you still need assistance.

#1569421

Hello, thank you for your help. However I am still getting the same result.Notice I did add the date format as in the example you referred me to.

My functions look as such:

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 );
				    $formated_date = date("F j Y", ($date));
				$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',10,2);
#1569445

It seems that you are not using the formatted date online 32. Use this:

$custom_title = $formated_date.' '.$last.' '.$first;

Instead of

$custom_title = $date.' '.$last.' '.$first;

Let me know if it works.

#1571599

Thanks for the help!