Problem: Create a cron job to export posts to a WordPress XML file on server
Your problem is that ob_file ain’t global. You only define it in c3m_export_xml(). Setting global $ob_file in ob_file_callback() gives you an empty file handle. Try this instead: function c3m_export_xml() { $args=array( ‘content’ => ‘posts’, ‘start_date’ => ‘october 2008’, ‘status’ => ‘published’); ob_start(); export_wp($args); $xml = ob_get_clean(); file_put_contents(‘server_path_to_my_file.xml’, $xml); }