0

I have a voting system on a custom post which uses AJAX, and I have a file that handles the AJAX request. This file is inside a sub folder named php of my theme. Hence the structure is:

../wp-content/themes/my-theme/php/ajax-handler.php

I use the following line to include the blog-header.php file:

include('../../../../wp-blog-header.php');

This works fine, but with debug mode on, I see warnings telling me that WP failed to open the stream as the file blog-header.php is non-existent.

So I tried this:

define('WP_USE_THEMES', false);

require('../../../../wp-blog-header.php');

Warnings gone, but $wpdb not recognized.

Any ideas on how to make this work without the warnings?

1 Answer 1

4

The "right way" is to not include it at all and use WordPress provided means for AJAX in themes and plugins.

1
  • Yes you're right about it, but I used this method when it was an emergency and I found it easier, but now that module is an integral part of a big system. Seems like I'm gonna have to use WP-AJAX after all! Thanks! Dec 15, 2011 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.