Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Forminator ➜ Voxel Sync (with CSV Mapping)
- * Description: Automatically transfers Forminator data to a "place" post type (GetVoxel), using an external mapping.
- */
- add_action('forminator_custom_form_after_save_entry', function ($entry_id, $form_id) {
- if ($form_id == 809) {
- if (!class_exists('Forminator_Form_Entry_Model')) {
- return;
- }
- $entry = Forminator_Form_Entry_Model::get_instance($entry_id);
- if (!$entry) {
- return;
- }
- $fields = $entry->get_fields();
- $data = [];
- // Retrieve data with their IDs
- foreach ($fields as $field) {
- $data[$field['name']] = $field['value']; // The 'name' field corresponds to the Field ID
- }
- // Use a relevant field as the title
- $post_title = sanitize_text_field($data['text-16'] ?? 'New listing'); // Example: text-16 should be adapted to the actual mapping
- // Author based on email, or current user
- $author_email = sanitize_email($data['email-1'] ?? ''); // Adapt to actual mapping
- $user = get_user_by('email', $author_email);
- $author_id = $user ? $user->ID : get_current_user_id();
- $new_post = [
- 'post_title' => $post_title,
- 'post_status' => 'publish',
- 'post_type' => 'place',
- 'post_author' => $author_id,
- ];
- $post_id = wp_insert_post($new_post);
- if ($post_id && !is_wp_error($post_id)) {
- // Actual mapping from the CSV file
- $mapping = [
- 'hidden-1' => 'submission_ID',
- 'hidden-3' => 'submission_date',
- 'hidden-4' => 'submission_time',
- 'radio-2' => 'creditor_profile',
- 'select-7' => 'creditor_individual_title',
- // ... Add other fields here as in the file
- ];
- foreach ($mapping as $field_id => $meta_key) {
- if (!empty($data[$field_id])) {
- update_post_meta($post_id, $meta_key, sanitize_text_field($data[$field_id]));
- }
- }
- }
- }
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement