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.

url of the post generated with Create content template

  1. jbdurand

    I would like to insert the url of the article within the post body of the article itself that will be generated with the "Post Content Template".
    I didn't find this function in the "insert form field" menu list.

    {embed_url} is the url of the page where the form is located
    {entry_url} is the url of the entry in the dashboard
    {post_edit_url} is the url of the articles list page for editing

    so is there any code for the url of the generated post?

    Best regards

    Posted 11 years ago on Sunday July 24, 2011 | Permalink
  2. Hi jbdurand. I was able to accomplish this using the gform_post_submission hook. The hook is documented here:

    That hook allows you to modify the post content after the entry is submitted. Since we have the post_id at that point (after the entry is submitted), it's pretty easy to access everything contained in the post object.

    Here's the code I used:

    // change the number 2 below to your form ID
    add_action('gform_post_submission_2', 'change_post_content', 10, 2);
    function change_post_content($entry, $form) {
        // get the post created by this form entry
        $post = get_post($entry['post_id']);
        // get title of the post
        $title = $post->post_title;
        // get the site url
        $url = site_url();
        // build the permalink
        $permalink = $url . '/?p=' . $entry['post_id'];
        // modify the post_content by appending the URL
        $post->post_content .= "\n<br style='clear:both;' />Permanent to this post: <a href='$permalink' title='Permanent link to $title'>$title</a>\n";
        // update post

    That code will be entered into your theme's functions.php. Here's some documentation on where to put this code.

    Here's the reference for the post object:

    Be sure to change the "_2" on the end of the gform_post_submission hook to your form ID, or remove the _2 altogether if you want this code to be run for all Gravity Forms forms on your site. If you need any more help, please let us know.

    Posted 11 years ago on Sunday July 24, 2011 | Permalink
  3. jbdurand

    Thank you for your code. It is working.
    Would it be possible to put a shortcode in the exact place of the (gravity generated) post where the url should appear?
    for the moment it appears at the end of the post.

    Posted 11 years ago on Thursday July 28, 2011 | Permalink
  4. Hello again. This part right here is what adds it to the end:

    $post->post_content .=

    The .= just appends it to the original post content. When you say "put a shortcode" do you mean the person submitting the form would enter the shortcode (which is a lot to expect of a visitor) or somehow you know where the link needs to be in the post body?

    In the latter case, if your post body is just one field it's going to be harder to do. You'd have to look for some text in the submission, then insert your link there. You would do that with a regular expression using this same code.

    If your content template (post body) is made up of various form fields, then it will be much easier to do, because you have knowledge of what's going to be into the post.

    Please post your content template here with a notation of where you want the URL and I will help you get the URL in there using this function. Thank you.

    Posted 11 years ago on Thursday July 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.