This code will get data from contact form 7 (form data) and before process of cf7 it will stored in db. This is use wp action “wpcf7_before_send_mail”.
add_action('wpcf7_before_send_mail', 'save_to_db'); function save_to_db($cf7) { global $wpdb; if (isset($_POST['propertyaddress'])) { $my_post = array( 'post_title' => wp_strip_all_tags($_POST['propertyaddress']), 'post_content' => $_POST['additional'], 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'jobs' ); $id_user = get_current_user_id(); if ($id_user == 0) { $id_user = $_POST['job_user_id']; } $user_id = array('0' => $id_user); $user_id = serialize($user_id); $redio_array = array(); $id = wp_insert_post($my_post, true); $jobs = $wpdb->get_results("SELECT * FROM bh_job_id_assignment WHERE post_id =" . $id); if (count($jobs) < 1) { $wpdb->insert('bh_job_id_assignment', array('post_id' => $id)); $job_id = $wpdb->insert_id; update_post_meta($id, 'assigned_job_id', $job_id); } /* Set post status default to pending */ wp_update_post( array( 'ID' => $id, 'post_status' => 'pending' ) ); /* update post mete will stored for acf fields */ update_post_meta($id, 'etate_agent_name', $_POST['estateagent']); update_post_meta($id, 'vendor_name', $_POST['vname']); update_post_meta($id, 'vendor_email', $_POST['vemail']); update_post_meta($id, 'vendor_telephone', $_POST['vtelephone']); update_post_meta($id, 'number_of_bedrooms', $_POST['numberofbedrooms']); update_post_meta($id, 'property_price', $_POST['propertyprice']); update_post_meta($id, 'services_required', $_POST['serviceRequired']); update_post_meta($id, 'assin_user', $user_id); update_post_meta($id, 'assigned_user_id', $id_user); update_post_meta($id, 'assin_user_vlaue', $user_id); update_post_meta($id, 'rd_button', $_POST['radio2']); } }