I have a button that, when clicked, needs to delete a specific entry from my WordPress DB via an ajax request.
If I disable jquery, everything works fine, but with jquery, the SQL query isn't getting processed correctly (or at all?).
I've put all of the necessary code (from multiple files) onto pastebin:
[[LINK href="http://pastebin.com/rrLseAbs"]]http://pastebin.com/rrLseAbs[[/LINK]]
Please read the comments carefully as I've explained everything there.
My speculation is not the information getting sent to the query is incorrect, so if anyone has an idea for how to display (with JS) the information that ajax is sending, that'd be a huge help.
Denzel Chia answers:
Hi,
Is there a possibility that $baseDir is wrong? or probably missing backslash. Causing AJAX sending data to wrong url?
Thanks.
Pippin Williamson comments:
When viewing the source, the URL to process-data.php is correct
Denzel Chia comments:
Another possibility, is you probably forgot to global $wpdb, before your sql query in process-data.php?
Thanks.
Pippin Williamson comments:
Ah! Though that doesn't immediately fix it, you saying that did make me realize that I was using an include function on process-data.php in the main plugin file, so globals were detected fine, but with an ajax request, those globals probably arn't loaded.
I'll let you know in a few.
Pippin Williamson comments:
Excellent! That's done it!
Larrie Bernd Rocha answers:
You can only use $wpdb when your PHP file is within the plugin or theme.
You need to declare these lines on top of your process-data.php.
define('WP_USE_THEMES', false);
require('../../wp-blog-header.php');
I assume that process-data.php is at [root]/includes/process-data.php.
Make sure that you have set the path for wp-blog-header.php correctly.
Also, make sure that $baseDir is correct.
Tests needed:
1. test your process-data.php if deletion works. Try a passing a sample ID.
2. test if clicking the button invokes
If these two works then you are good.