Created
April 9, 2014 15:35
-
-
Save roseg43/e408c29d680e9f3bfc6f to your computer and use it in GitHub Desktop.
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 | |
/* When a form is submitted, create two custom posts */ | |
function after_gform_submit($entry, $form) { | |
$isInteraction = false; | |
$interaction_type_id; | |
$supporter_email_id; | |
foreach($form["fields"] as $field) { | |
if ( $field["label"] == "Interaction Type" ) { | |
$isInteraction = true; | |
$interaction_type_id = $field['id']; | |
} | |
if ( $field["label"] == "Email") { | |
$supporter_email_id = $field["id"]; | |
} | |
} | |
$supporter_email = $entry[(string)$supporter_email_id]; | |
$interaction_type = $entry[(string)$interaction_type_id]; | |
if ( $isInteraction ) { | |
/* Create the interaction post */ | |
$interaction_post_args = array( | |
'post_type' => 'interaction', | |
'post_status' => 'publish' | |
); | |
$post_id = wp_insert_post ( $interaction_post_args ); | |
$interaction_meta_values = array( | |
'interaction-type' => $entry["28"], | |
'who_did_you_interact_with' => $entry["post_id"] | |
); | |
if($post_id > 0) { | |
foreach($interaction_meta_values as $key => $value) { | |
update_post_meta($post_id, $key, $value); | |
} | |
} | |
} | |
} | |
// Call function after the form is submitted | |
add_action('gform_after_submission', 'after_gform_submit', 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment