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.

Populate a Custom Field with {entry_id}

  1. I need to populate a Custom field with the {entry_id} but this doesn't seem possible?

    I can see that one can populate the Title and Body part with {entry_id} but I need to do it with a Custom Field.

    Any way to do this?

    Posted 11 years ago on Monday September 3, 2012 | Permalink
  2. Just type that in to the default value for the custom field. It may not be available in the drop down of merge tags, but it will work. I just did it and it worked for me. The post custom field holds the entry ID. One anomaly is that the field in the entry continues to hold the default value of {entry_id} but that does not matter much, since you have the entry ID available in the ID already.

    Posted 11 years ago on Monday September 3, 2012 | Permalink
  3. Chris..Thank you for your reply but it doesn't seem to work. I did the following:

    1. In my GF Form I created a Custom Field with the Field Type set to Single Line Text
    2. In the Custom Field Name I selected New and entered the field value as Entry_ID
    3. I clicked on the Advanced Tab and in the Default Value I entered {entry_id}
    4. I saved my form and opened a preview
    5. Completed the form and submitted the form
    6. When I go to the post the Custom field called Entry_ID is there and it's value is {entry_id}
    7. I the edited my single.php file to include the Custom field by using
    <?php echo get_post_meta($post->ID, 'Entry_ID', true); ?>
    8. Saved the form and viewed the post

    The custom field then still only showed the text "{entry_id}" and not the actual ID number of the Entry.

    What I need is the Custom Field to actually save and display the GF Form Entry ID as a Number in my post. Something like 6 or 13.

    Posted 11 years ago on Tuesday September 4, 2012 | Permalink
  4. Here is the form I tested on:
    http://gravity.chrishajer.com/test-line-breaks/ (password gravity)

    After you submit, you will have a link to the category, and the most recent post will be yours. At the bottom of your story submission, you will see This was entry #971 where the 971 is your actual entry ID. Here is a post I created using this form. You can download a copy of the form here http://pastebin.com/0dFB3Yp1 (select the raw or download link.)

    Your experience was different than mine. What you want is exactly what I did. The entry ID was stored in my custom field. Can you please send me a WordPress admin login for your site and I will take a look. Thanks.

    Posted 11 years ago on Tuesday September 4, 2012 | Permalink
  5. Jacques, I replied to your email. I installed my form on your server and created three posts, all of which have the Entry ID in the body of the post.

    Posted 11 years ago on Wednesday September 5, 2012 | Permalink
  6. I received your email. To store the entry ID as a custom field in the post, not just use the entry ID in the post, you can use the gform_after_submission hook. See this code:

    [php]
    add_action('gform_after_submission_9', 'save_entry_id', 10, 2);
    function save_entry_id($entry, $form){
        update_post_meta($entry['post_id'], 'gfentryid', $entry['id']);
    }

    That will write the entry ID to a custom field with a meta key of "gfentryid" and save it with the post. Then you can do whatever you want with it in your template. Change the 9 in line one to your form ID.

    Also, you can delete the hidden field and the reference to it in the content template.

    Posted 11 years ago on Thursday September 6, 2012 | Permalink
  7. Chris

    GREAT..GREAT...THANK YOU

    Just tested and works great! Another reason why I just love GF... Excellent support!!

    Posted 11 years ago on Thursday September 6, 2012 | Permalink
  8. You're welcome. Sorry I missed it the first time around.

    Posted 11 years ago on Thursday September 6, 2012 | Permalink

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