Skip Navigation

[Resolved] How to update custom field from front end button click

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2586413

Tell us what you are trying to do?
I'm developing a site that users need to complete a checklist of items, which unlocks a quiz. I have this all setup using a CPT called 'checklist' with a range of items the user completes with custom fields. Once complete, they have access to a quiz which is done with Gravity Forms.
On completion of the quiz (ie when they hit the submit button) I want to update some fields in the user's related Checklist post. Things like how many attempts have they made (field 'test-fails', and the time (field 'last-attempt').
Unfortunately I have no idea what sort of code I use to target and edit the fields like this.

I was trying to use
add_filter( 'gform_submit_button', 'your_function_name', 10, 2 );
to initiate everything, but I have no idea what to put in this?

thanks

#2586471

Hello,

Since you are using Gravity Forms to setup the quiz, it is better to check their support if there is any feature for it.

In my opinion, you can consider custom codes, for example:
1) When user hit the submit button, use custom JS code send AJAX call with related information:
https://codex.wordpress.org/AJAX_in_Plugins

2) In server side, get the AJAX call related information, and update the custom field value:
https://developer.wordpress.org/reference/functions/update_post_meta/

#2586473

Thanks, I think I'm ok with how to trigger it from the Gravity Forms side, I'm trying to figure out how do I target the relevant post belonging to the user that holds their custom fields.

#2587873

How do you setup the "user's related Checklist post"?

If the Checklist post's author is current logged-in user, you can use WordPress built-in function get_posts() to get hist own "Checklist post" with post author filter, see WP document:
https://developer.wordpress.org/reference/functions/get_posts/
https://developer.wordpress.org/reference/classes/wp_query/#author-parameters