[wp-hackers] ajax and $wpdb

Simon Wheatley simon at sweetinteraction.com
Wed Jul 29 18:05:23 UTC 2009

Others have answered the AJAX question, but for completeness
wp-load.php is what you wanted rather tha wp-blog-header.php.

However to add my tuppenny-worth, and this is why the AJAX solutions
mentioned are more cleverer, you can't guarantee the relative location
of wp-load.php to your plugin files (they might have moved wp-content
outside the main WP files, etc, etc)... so to get that to work you'd
have to have someone edit the plugin files to specify the location...
and then when someone uses the nifty cool "update plugin" feature all
the edits would be overwritten and the plugin breaks. This last point
is why we all need to drill "never edit plugin files" into people as
thoroughly as we've been drilling "never hack core".


On Wed, Jul 29, 2009 at 11:26 AM, Adam Taylor<adamjctaylor at gmail.com> wrote:
> Hi All,
> I'm using AJAX to call my plugin script to process data and update what is
> displayed (essentially a thumbs up/thumbs down voting plugin).  This is
> fine, I can update the text but I need to also interact with the database.
> As I understand, because I am calling my script directly not from within
> wordpress $wpdb is not available.
> I read that you can include wp-blog-header.php and everything should be
> available and have added - require_once('../../../wp-blog-header.php');  -
> to the function requiring it, however, I get the following error:
> PHP Fatal error:  Call to a member function set_prefix() on a non-object in
> /dev/site/wp-settings.php on line 255
> Firstly: what's going on here and how can I fix it?
> Secondly: is this the best way of doing this? I can't find any tutorials or
> documents about writing an ajaxy plugin for wordpress that interacts with
> the database. This topic http://wordpress.org/support/topic/184095 suggests
> that it is not but I don't understand the suggested solutions.
> Thanks in advance,
> Adam

Sweet Interaction Ltd is Registered in England/Wales, no. 6610741
Registered office: 7 Malton Av, Manchester, M21 8AT

More information about the wp-hackers mailing list