Skip Navigation

[Resolved] Auto complete post title based three fields. Date field is showing random value

This support ticket is created 3 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
- 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 AndreG3332 3 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1940433

Hy guys,
I have a code snippet that I use to autocomplete a post title from a cred form. It works however I have one problem. Here is the code I use.

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */
 
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
 
// Put the code of your snippet below this comment.
 
add_action('cred_save_data', 'func_auto_post_name',10,2);
function func_auto_post_name($post_id, $form_data) {
  
if ($form_data['id']==798) {
        $surname = get_post_meta($post_id, 'wpcf-student_surname', true);
        $first_name = get_post_meta($post_id, 'wpcf-student-first-name', true);
  	$date_of_birth = get_post_meta($post_id, 'wpcf-date-of-birth-participant1', true);
        $cptitle= $surname. ' - ' . $first_name. ' - ' . $date_of_birth;
        $args = array('ID' => $post_id, 'post_title' => $cptitle);
        wp_update_post($args);
    }
  
}

My problem is with the date of birth. I do use a date field for this form. Once the form is updated it displays the entry. with the auto-created post title. The issue is that instead of the date being part of the post title it is just some numerical value. Any idea how i can
fix this issue.

Regards

#1940695

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Just to let you know that Types date field value stored as Unix timestamp into the database.

To display the formatted date you will require to convert the timestamp to date.

Please try to replace your existing code with the following code:

add_action('cred_save_data', 'func_auto_post_name',10,2);
function func_auto_post_name($post_id, $form_data) {
   
if ($form_data['id']==798) {
        $surname = get_post_meta($post_id, 'wpcf-student_surname', true);
        $first_name = get_post_meta($post_id, 'wpcf-student-first-name', true);
    $date_of_birth = get_post_meta($post_id, 'wpcf-date-of-birth-participant1', true);

  // convert date untix timestamp to date
   $date_of_birth = date("Y-m-d", $date_of_birth);

        $cptitle= $surname. ' - ' . $first_name. ' - ' . $date_of_birth;
        $args = array('ID' => $post_id, 'post_title' => $cptitle);
        wp_update_post($args);
    }
   
}

I hope this will help you to resolve your issue.

#1941327

My issue is resolved now. Thank you! Thx Minish Appreciate your assistance