I have working code that is adding the date field to the post title, with a CRED form, but I am not sure on how to get it to format as an actual date.
//Create a dynamic post title by the CRED form.
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==1911) {
$date = get_post_meta($post_id, 'wpcf-meeting-date', true);
$title= 'Council Meeting' . $date;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}
Instead of getting a number string I would like to get something like "April 13 2020"
Hello and thank you for contacting the Toolset support.
You will need to use the date function to format the date into a string, for example, date("F j Y", strtotime($date)). Check all the possible format options here hidden link
The code will be like:
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==1911) {
$date = get_post_meta($post_id, 'wpcf-meeting-date', true);
$formated_date = date("F j Y", strtotime($date));
$title= 'Council Meeting' . $formated_date;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}
I hope this helps. Let me know if you have any doubts.
Jamal,
It is not picking up the date from 'wpcf-meeting-date' so no matter the date I select it is returning "Council Meeting January 1 1970"
I'll need to get a closer look at your fields and your code to be able to help with this.
** Please make a FULL BACKUP of your database and website.**
I would also eventually need to request temporary FTP access to recover the site in case of an error while testing. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
Your next reply will be private which means only you and I have access to it.
I have checked the current entries and everything seems correct. I'll need to use PHP debugging for further analysis so I am activating the private reply for FTP access. You can invite me using my address jamal.b(at)onthegosystems.com
Thank you for the invitation to collaborate. I activated PHP debugging from the backend for my tests.
The code has actually an error, my mistake, we should not use the strtotime function. I updated the code snippet and it worked.
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==1911) {
$date = get_post_meta($post_id, 'wpcf-meeting-date', true);
$formated_date = date("F j Y", $date);
$title= 'Council Meeting - ' . $formated_date;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}
My apologies for the inconvenience.
That does the job, Thanks.