Hello, i want to store a counter in a custom field with PHP.
I tried this https://www.advancedcustomfields.com/resources/update_field/
But i think it only updates fields that were previously added to a group.
How can i do this without adding the field to a group?
Or shall i just create a new group with nothing but the counter field and add it to a random empty page?
Or maybe use WP built in custom fields? I tried that first but it didn’t save the new field either. I’m so confused.
ACF cannot save values to fields that have not been created in a group. ACF also cannot get values from the field. To use fields that do not exist in an ACF field your you need to use standard WP function like add_post_meta(), update_post_meta(), get_post_meta().
Alright. Got it. Now I know not to try it.
I’ll use wp functions.
I investigated the reason of those not working. I can’t just use those wp functions on an Ajax called plugin. I must create a function and call admin-ajax.php in the js, also there must be an action with the name of the function that needs to run. I’ll try when I get the time I hope it works!
This is solved.
Yes, all ajax requests in WP need to go through admin-ajax.php. the best source of information on ajax in WP is here https://codex.wordpress.org/AJAX_in_Plugins