I've been developing for some time on a plugin
in wordpress
, but one problem keeps bugging me. I want to export a database-table as an excel file and therefor i need access to the global $wpdb->variable
from a file in my plugin directory.
I found a blog entry that explains what classes i should include, but this doesn't work (link is below). As you can see, i do a var_dump
, but it never reaches that point. If i leave the includes of wp-config
and wp-load
out of the code, the dump returns NULL
, so i'm guessing there is a problem with the imports.
Anyway, i was hoping someone could help me with this problem. I don't necessarily need a fix for my approach, I just need a way to export an array of data (fetched from my db) to excel in wordpress. Any help would be appreciated. Thanks in advance.
http://www.notesbit.com/index.php/web-mysql/web-scripts/standalone-access-the-wordpress-database-using-wpdb/
include_once('../../../wp-config.php');
include_once('../../../wp-load.php');
include_once('../../../wp-includes/wp-db.php');
var_dump($wpdb);
$filter = get_where_clause();
$order = get_order_by_clause();
$data = $wpdb->get_results("SELECT * FROM " . $table_prefix . "team_data" . $filter . $order, ARRAY_A);
$result = array();
EDIT:
I cannot include the wp-config
, it gives constant errors. I know where the bug is taking place, I just need to find a work-around. when looking at the wp-settings
page (which is included by the wp-config) you will find this line of code:
foreach ( wp_get_active_and_valid_plugins() as $plugin )
include_once( $plugin );
unset( $plugin );
this is where there is a bug. I just don't know how i should work around this bug.
EDIT 2:
Problem solved. When including the file, i included the wp-config
more than once (even though i stated it should only be included one time). I solved the problem by using the following code.
global $wpdb, $table_prefix;
if(!isset($wpdb))
{
require_once('../../../../wp-config.php');
require_once('../../../../wp-includes/wp-db.php');
}