add_action('cf7_2_post_form_submitted_to_post', 'new_post_mapped',10,4);
/**
* Function to take further action once form has been submitted and saved as a post. Note this action is only fired for submission which has been submitted as opposed to saved as drafts.
* @param string $post_id new post ID to which submission was saved.
* @param array $cf7_form_data complete set of data submitted in the form as an array of field-name=>value pairs.
* @param string $cf7form_key unique key to identify your form.
* @param array $submitted_files array of files submitted in the form, if any file fields are present.
*/
function new_post_mapped($post_id, $cf7_form_data, $cf7form_key, $submitted_files){
wp_update_post(
array (
'ID' => $post_id,
'post_date' => $cf7_form_data["start-date-closing"],
'post_date_gmt' => get_gmt_from_date( $cf7_form_data["start-date-closing"] )
)
);
}
Ok, So I added the above to my functions and it works to schedule the post for a future date. BUT, when this code is active the meta post mappings don’t work anymore. I need to write 2 custom fields and they work if the above is disabled, but stop working when it’s enabled. I also have the
add_filter( 'cf7_2_post_status_post', 'publish_new_post',10,3);
/**
* Function to change the post status of saved/submitted posts.
* @param string $status the post status, default is 'draft'.
* @param string $ckf7_key unique key to identify your form.
* @param array $submitted_data complete set of data submitted in the form as an array of field-name=>value pairs.
* @return string a valid post status ('publish'|'draft'|'pending'|'trash')
*/
function publish_new_post($status, $ckf7_key, $submitted_data){
/*The default behaviour is to save post to 'draft' status. If you wish to change this, you can use this filter and return a valid post status: 'publish'|'draft'|'pending'|'trash'*/
return 'publish';
}
code set as well in functions.
So, is there an error in my code? or is there a bug/issue in the plugin when these are both running?