2

Goal: Update wpdb each time a user clicks on a specific button.

Every time a user clicks on a button, I need jQuery to run a function that will update my wordpress database. As far as I understand, this must be done through an AJAX request sent to a php file residing on the server. This article seems to address my issue, but I am having trouble interpreting exactly what it is I need to do.

A couple of my questions are as follows:

  1. I will need a php file that will be called from the jQuery function, but where should that file be housed? I believe it should be at http:mysite.com/phpfile.php, but how can I get the file to be housed at that location?
  2. What exactly should this php file consist of?

If someone is able to give me the steps needed to accomplish this goal, I would be forever grateful. Thanks!

7
  • Have you considered using the REST API instead? You want to avoid having a PHP file you ping, it has maintenance, security, and other issues related to it
    – Tom J Nowell
    Apr 20, 2017 at 22:31
  • @TomJNowell I was under the impression that you could not change the db through the API. Is that incorrect?
    – gidgicken
    Apr 20, 2017 at 22:38
  • @TomJNowell It looks like the API only has the ability to change Wordpress' core tables. I have a custom table that I'm attempting to access. Could I accomplish that through a custom API endpoint?
    – gidgicken
    Apr 20, 2017 at 22:59
  • You can add custom endpoints with the register_endpoint function
    – Tom J Nowell
    Apr 20, 2017 at 23:50
  • @TomJNowell Can't this option cause security issues? Updating DB with jQuery?
    – Johansson
    Apr 21, 2017 at 1:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.