I've been working on a custom post type meta-box implementation that allows me to change the post_date to match the value in my "date" meta-box.
The function works perfectly except when I try to add a new custom post, I receive a blank page! I know it's this function because if I remove it, I can create a new post no problem.
Here is my function:
function cfc_reset_postdate( $data ) {
// If it is our form has not been submitted, so we dont want to do anything
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if($data['post_type'] == 'scripture-memory') {
$date = $_POST['cfc_date'];
$date = DateTime::createFromFormat('D - M j, Y', $date);
$date = $date->format('Y-m-d');
$data['post_date'] = $date;
return $data;
}
}
add_filter( 'wp_insert_post_data', 'cfc_reset_postdate', '99', 1);
Any ideas on why I'm receiving a blank page when trying to create a new post?
EDIT:
I've changed my code to reflect your ideas:
function cfc_reset_postdate( $data ) {
//if($data['post_type'] == 'scripture-memory') {
if($_POST['cfc_date'] != '') {
$date = $_POST['cfc_date'];
$date = DateTime::createFromFormat('D - M j, Y', $date);
$date = $date->format('Y-m-d');
$data['post_date'] = $date;
return $data;
}
//}
}
add_filter( 'wp_insert_post_data', 'cfc_reset_postdate', '99', 1);
Only problem is when I create a new post, it only allows me to create a draft, and then it comes up with a blank page that says "Are you sure you want to do that?"
I'm going to work on this more, it looks like we're making progress. Thanks everybody for your help!
if
statement? (/*if($data['post_type']...){...}*/
)