Skip Navigation

[Résolu] Updating Post Title With Custom Date Field Value in Readable Format

This support ticket is created Il y a 6 années. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par julieP Il y a 6 années.

Assisté par: Minesh.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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!