PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Post template condition based on field

  1. I am pretty sure such an obvious question was answered before, but I was not able to find the right topic.

    Lets say I have an "http" field in my form. I am using post template to make a post and publish it.
    I want to have "Source: -http-" in the post, where -http- is the value of http-field.

    The thing is http field is optional. So there can be no input at all. In such case I would not like to have just "Source: " printed on the page.

    So how it is possible to display or hide code ("source: " in the case) based on whether there is anything in the http-field or not?

    Posted 12 years ago on Wednesday August 31, 2011 | Permalink
  2. The post template does not support conditionals like that (for example, if the field is empty, don't print the Source heading.) I did work up an example recently using the gform_post_submission hook:

    Add this code to your theme's functions.php
    http://pastebin.com/VverkM3E

    • Change the 9 on line 4 to your form ID.
    • Line 7 grabs the post that was just created
    • On line 10, the '4' corresponds to the field whose value you want to use as "Source." That would be your http field and when it's present (line 10 checks for this), output the "Source: " heading and then the URL after (line 11)
    • Line 13 updates the post
    • I needed lines 15 - 18 since I needed to clear an image, whether or not there was a Source (http) submitted

    I hope that helps point you in the right direction.

    Posted 12 years ago on Wednesday August 31, 2011 | Permalink