0 %
Khalid Bin Ahsan
Full Stack Web Developer
image
  • Email
  • developer@khalidbinahsan.com
  • Whatsapp/Call
  • +8801754879302
Skills
PHP
Laravel
Wordpress
html
CSS
Js
Jquery
Bootstrap
Sass
  • Version Control (Git)
  • Photoshop
  • Adobe Illustrator
  • Filmora

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.

Write a comment

Category

Latest Posts

Stay Connected

About Me

web developer

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