P.S. I removed the time. It is published to Pending Review. However, the post date is not replace default date. Please advise. Thank you.
Code:
add_filter("gform_post_data", "set_post_date", 10, 3);
function set_post_date($post_data, $form, $entry){
//only do this when the form id is 2
if($form["id"] != 2)
return $post_data;
//set post date to field on form if date provided; get from entry data
//using a date field in mm/dd/yyyy format and a time field in 24 hour format
$date_value = $entry["9"]; //pull the date value from the form data posted, field 9 on my form
//$time = $entry["7"]; //pull the time value from the form data posted, field 7 on my form
//only change post date/time when a date has been chosen
if (!empty($date_value))
{
//convert post date to the appropriate format so it will be inserted into the database
$post_date = date("Y-m-d H:i:s",strtotime($date_value . " " . $time_value));
$post_data["post_date"] = $post_date; //set the post_date
}
return $post_data; //return the changed data to use when the post is created
}
Posted 11 years ago on Monday June 3, 2013 |
Permalink