Advertisement
chrishajer

modify $post if there are values submitted in certain fields

Dec 19th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. // http://www.gravityhelp.com/forums/topic/if-statement-in-content-template
  2. // conditionally modify the post body if there is a document uploaded or a URL submitted
  3. // if there is a document uploaded in $entry[6], then link to it with the text "Additional Information"
  4. // if there is a URL submitted in $entry[5], then link the text to the external website
  5. add_action('gform_after_submission_1', 'conditional_content_template_one', 10, 2);
  6. function conditional_content_template_one($entry, $form){
  7.         $post = get_post($entry['post_id']);
  8.         // if either field 6 or field 5 has a value, then add the "additional information" header
  9.         if(($entry[6]) <> '' || ($entry[5] <> '')) {
  10.                 $post->post_content = "$post->post_content\n<h4>Additional Information</h4> ";
  11.                 // field 6 == document upload
  12.                 if($entry[6] <> '') {
  13.                         $post->post_content = "$post->post_content\n<a href='$entry[6]' title='Additional documentation for $entry[1]'>Uploaded documentation</a><br class='clear' />";
  14.                 }
  15.                 // field 5 == URL
  16.                 if($entry[5] <> '') {
  17.                         $post->post_content = "$post->post_content\n<a target='_blank' href='$entry[5]' title='Visit external website for $entry[1]'>$entry[5]</a><br class='clear' />";
  18.                 }
  19.         wp_update_post($post);
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement