Skip Navigation

[Resolved] Updating Post Title With Custom Date Field Value in Readable Format

This support ticket is created 6 years, 1 month 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
- 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 julieP 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1153706

I'm trying to update the post title when a form is submitted with the value of a custom date field. Here's my hook so far:-

add_action('cred_submit_complete', 'after_save_data_form_485',10,2);
function after_save_data_form_485($post_id, $form_data)  {
    
       if ($form_data['id']==485)    {
        
        //get custom date field
        $custom_date = get_post_meta($post_id, 'wpcf-custom-date', true);
		
        // create array
        $new_title = array(
            'ID'           => $post_id,
            'post_title'   => $custom_date,
            );
            
        // Update post title
        wp_update_post( $new_title );
  }
}

As it stands, the updated post title becomes the timestamp. Is it possible to convert this into a readable format, e.g. 20 Aug 2019 (in a types field this would be 'd M Y' format)?

#1153771

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Actually - Types date field value saved as Unix Timestamp. So if you want to display the formated date you need to convert the Unix Timestamp to formated date.

Could you please try to use folloowing code and try to resolve your issue.

add_action('cred_submit_complete', 'after_save_data_form_485',10,2);
function after_save_data_form_485($post_id, $form_data)  {
     
       if ($form_data['id']==485)    {
         
        //get custom date field
        $custom_date = get_post_meta($post_id, 'wpcf-custom-date', true);
        $custom_date = date("d M Y",$custom_date);
         
        // create array
        $new_title = array(
            'ID'           => $post_id,
            'post_title'   => $custom_date,
            );
             
        // Update post title
        wp_update_post( $new_title );
  }
}
#1154580

Thanks Minesh - that worked a treat!