[wp-hackers] ajax and $wpdb

Adam Taylor adamjctaylor at gmail.com
Wed Jul 29 10:26:32 UTC 2009


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

-- 
adamjctaylor at gmail.com
http://www.twitter.com/adamtaylor


More information about the wp-hackers mailing list