In advance of this evening’s WordPress Knoxville meetup on Writing a WordPress Plugin, I’m posting my favorite method for handling AJAX requests in WordPress plugins and themes. The following gist addresses where you send your AJAX requests when you’re making an AJAX call inside a WordPress plugin or theme.
The following code added to your theme or plugin allows WordPress to handle the above request:
NOTE: In order for the above code to work, you’ll need to flush your WordPress rewrite rules. Short of adding some code to your theme/plugin to do this, the quickest way to flush your rewrite rules is to visit
Settings > Permalinks. Whenever that page loads,
flush_rewrite_rules() is called.
UPDATE 11/26/2013 (06:09): At last night’s WordPress Meetup, Chris Lamm showed me the preferred way to make an AJAX request in WordPress. Here’s some further details on how to make use of the feature Chris outlines in his afore-linked-to example.