I am trying to call one of the built in functions within a custom php function but it isn’t working, I am assume I need to somehow declare this function as global but I’m not really sure what I am doing.
what I want to do is query one of the tables in the wordpress database and create a csv file that the user can download.
I have come up with this code:
function exportCsv()
{
$file = "Export.csv";
$fh=fopen($file,"w+") or die ("unable to open file");
$query = "select * from " . $wpdb->prefix . "newsletter";
$recipients = $wpdb->get_results($query . " order by email");
for ($i=0; $i
$row = $recipients[$i]->email . ',' . $recipients[$i]->name .
',' . $recipients[$i]->status . ',' . $recipients[$i]->token . '"nr';
$row = str_replace('"', "'", $row);
fwrite($fh, $row, strlen($row));
}
fclose($fh)
}
The problem is that $wpdb is not working within my custom function. I’m sure this is simple but I learning this as I go along.
Thanks