Advertisement
chrishajer

Add the post ID to a custom field after_submission

Aug 21st, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. // Insert the post ID into a custom field after the entry and post are created
  3. // Help Scout 29933
  4. // References:
  5. // http://www.gravityhelp.com/documentation/page/Gform_after_submission
  6. // http://codex.wordpress.org/Function_Reference/get_post_meta
  7. // http://php.net/manual/en/function.str-replace.php
  8. // http://codex.wordpress.org/Function_Reference/update_post_meta
  9. // change the 411 here to your form ID
  10. add_action('gform_after_submission_411', 'update_custom_field', 10, 2);
  11. function update_custom_field($entry, $form) {
  12.     // the post ID of the recently created post
  13.     $pid = $entry['post_id'];
  14.     // the meta key for the custom field we want to update
  15.     $key = 'portfolio_item_description';
  16.     // the placeholder text we are searching for
  17.     $needle = 'PORTFOLIOPOSTID';
  18.     // the content we are going to search within
  19.     $haystack = get_post_meta($pid, $key, TRUE);
  20.     // the modified content
  21.     $new_description = str_replace($needle, $pid, $haystack);
  22.     // insert the modified content back in the custom field
  23.     update_post_meta($pid, $key, $new_description);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement