Created
March 25, 2020 06:28
-
-
Save finalwebsites/4c9eb0da817cfc360637f52ac38b2f90 to your computer and use it in GitHub Desktop.
Store Elementor form submissions using a custom post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// place this code into you child theme's functions.php file | |
// Do you use Advanced Custom Fields? Uncomment the next row, otherwise the custom fields meta box doesn't show up in your edit post screen | |
//add_filter('acf/settings/remove_wp_meta_box', '__return_false'); | |
add_action( 'init', 'fws_elementor_submissions_post_type' ); | |
function fws_elementor_submissions_post_type() { | |
$args = array( | |
'public' => false, | |
'show_ui' => true, | |
'label' => __( 'Form submissions', 'textdomain' ), | |
'menu_icon' => 'dashicons-feedback', | |
'supports' => array( 'title', 'custom-fields' ), | |
'capabilities' => array( 'create_posts' => false ), | |
'map_meta_cap' => true | |
); | |
register_post_type( 'elem_forms_submit', $args ); | |
} | |
add_action( 'elementor_pro/forms/new_record', function( $record, $handler = null ) { | |
$subject = $record->get_form_settings( 'email_subject' ); | |
$my_post = array( | |
'post_title' => $subject, | |
'post_type' => 'elem_forms_submit', | |
'post_status' => 'publish', | |
'post_author' => 1 | |
); | |
if ($post_id = wp_insert_post( $my_post )) { | |
$raw_fields = $record->get( 'fields' ); | |
foreach ( $raw_fields as $id => $field ) { | |
update_post_meta( $post_id, $id, $field['value'] ); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Form submissions are stored now by Elementor.
Tip! Use this code example (with some changes) if you need to build a front-end submission function with an Elementor form.