I have a Gravity Form with a user registration plugin installed, so every time someone completes the form, they are added as a user and the submitted form is assigned an entry ID which is linked to that user. But whenever a user re-submits the form a new entry ID is created – there is a column in the "wp_gf_entry" table called "created_by" which contains the user ID for who submitted the form. So I figured I need to find currently logged in user ID, match it against the "created_by" column then find the highest value entry ID for that user, which I will then need to display in a shortcode.
I have figured out how to find the initial entry ID which is linked to the users meta details and display that inside the shortcode, see below.
$ user_id = get_current_user_id(); $ key = 'entry_id'; $ single = true; $ gform = get_user_meta( $ user_id, $ key, $ single ); echo do_shortcode('[gravitypdf id="5ffc7508269e7" entry="' . $ gform . '" text="Download"]');
This would work great if the entry ID got updated every time the user re-submits the form, as the entry ID would always stay the same, but a new entry ID gets created for every form submission.
That led me to searching for another solution which would update the same entry every time the user re-submitted the form, but I was at a lose and could only find the following gform_entry_id_pre_save_lead which after testing wouldn’t work for me and a new entry was created each time.
Ideally I would prefer the first solution, just in case the user needs to access an older entry. Although its not essential so all suggestions and possible solutions are welcome.
I’m relatively new to PHP, but feel like the solution Is not far away and feel like the use of the foreach loop and the max() function will help with looping through the array of entry IDs for current user and finding the max value in that array…I just can’t figure out how to get there with code!
Any help would be appreciated.