I am writing a wordpress plugin for my wordpress site and am getting trouble comprehending the jquery ajax demands. The bottom line is, I'm looking to get some user meta data loaded once the page loads.

So during my javascript file I've got a line:

$.getJSON("http://mysite.co.uk/wp-content/plugins/myplugin/ajax/ajax.php?action=test", function(json) { // do stuff });

Therefore the above DOES get known as, but it is the PHP code I am getting challenge with. Within the file ajax.php, I'm creating a database call, but No usual class details are available. I have attempted such as the admin ajax page, many other pages from the own wordpress plugin (which works).... unsure what else to complete!

The database call method works OK during my wordpress plugin code.. however i reckon that the ajax.php file is outdoors the Wordpress framework so this is exactly why it isn't working... but I'm not sure ways to get it Within the framework!?

I simply need to make use of the $wpdb->get_results($sql); command to obtain my SQL. The mistake came back from firebug is that i'm creating a call for an undefined function.

Thank you for any help...

Look at this page, essentially you only have to define a callback to have an action and employ the already defined Wordpress machinery.