Advertisement
chrishajer

conditional content template based on field submission

Aug 30th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1.  
  2. // http://www.gravityhelp.com/forums/topic/post-template-condition-based-on-field
  3. // change the number 9 here to your form ID
  4. add_action('gform_post_submission_9', 'conditional_content_template_nine', 10, 2);
  5. function conditional_content_template_nine($entry, $form){
  6.     // $post will contain the full WordPress Post that was created
  7.         $post = get_post($entry['post_id']);
  8.     // $entry[4] is equivalent to your Source field.  Change the number to match your Source field
  9.     // if $entry[4] is not empty, then change the post content
  10.         if($entry[4] <> '') {
  11.                 $post->post_content = "$post->post_content <p>Source: <a href='$entry[4]' title='$post->post_title additional information'>$entry[4]</a></p><br class='clear' />";
  12.         // be sure to save the updated post
  13.                 wp_update_post($post);
  14.         }
  15.         else { // clear the image with a br
  16.         // I need to clear an image in my post whether or not there is a Source
  17.                 $post->post_content = "$post->post_content <br class='clear' />";
  18.                 wp_update_post($post);
  19.         }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement