Contact form 7 to new post on your custom post type
Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on pinterest
Share on telegram
Share on tumblr
Share on skype
Share on reddit
Share on pocket
Share on print
// Contact form to Custom Post Type
function create_member_post_from_submission($contact_form) {
if ($contact_form->id() == 123) { // Replace 123 with your contact form ID
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$form_data = $submission->get_posted_data();
$member_data = array(
'post_title' => sanitize_text_field($form_data['first-name']) . " " . sanitize_text_field($form_data['last-name']),
'post_type' => 'Your_post_type', //Your post type name will be here
'post_status' => 'publish',
);
$member_post_id = wp_insert_post($member_data);
// Check if the post was created successfully
if (!is_wp_error($member_post_id)) {
// Update ACF fields
update_field('street_address', sanitize_text_field($form_data['street-address']), $member_post_id);
update_field('street_address_line_2', sanitize_text_field($form_data['street-address-line-2']), $member_post_id);
update_field('city', sanitize_text_field($form_data['city']), $member_post_id);
update_field('state', sanitize_text_field($form_data['state']), $member_post_id);
update_field('postal_code', sanitize_text_field($form_data['postal-code']), $member_post_id);
update_field('email', sanitize_text_field($form_data['email']), $member_post_id);
update_field('phone', sanitize_text_field($form_data['phone']), $member_post_id);
update_field('comment', sanitize_text_field($form_data['your-message']), $member_post_id);
// Send email notifications to the admin here if needed
}
}
}
}
add_action('wpcf7_mail_sent', 'create_member_post_from_submission');
Tags
Have any questions? Contact Me or left your comment below.
Category
Latest Posts
-
How to block a site from your PC hosts
-
How to install Vue js in your machine
-
Contact form 7 to new post on your custom post type
-
Maximize Your Site's Potential: How to Increase WordPress Maximum Upload File Size
-
Solve All-In-One WP Migration Stuck While Importing with These Easy Simple Steps
-
Boost Your Website Design with Elementor Pro: Free Download Available Now!
Stay Connected
About Me
Khalid Bin Ahsan
Full Stack Web Developer
My expertise spans across a range of technologies and platforms, including HTML, CSS, JavaScript, jQuery, Bootstrap, PHP, Laravel, and WordPress. With this extensive knowledge and hands-on experience, I have helped numerous clients and businesses develop and optimize their web presence to achieve their goals.. Learn More
Recent Comment
Khalid Bin Ahsan © 2024 All Rights Reserved
Email: developer@khalidbinahsan.com