Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End calling wordpress funtion from custom fuction

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #30945
    cheese
    Member

    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

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.