I am making a theme for myself so I have made simple theme options for customization I just want to add export function triggered by a button. I have checked these two examples

  1. Problem: Create a cron job to export posts to a WordPress XML file on server
  2. How can I get an XML export of my 1K+ posts WordPress instance?

but these do not work. I want to make a function that on click export all the data in the XML file. How can I achieve that?


Example code 1:

require(dirname(dirname(__FILE__)) . '/wp-load.php');
require(ABSPATH . 'wp-admin/includes/admin.php');
require_once( ABSPATH . 'wp-admin/includes/export.php' );
$xml = ob_get_clean();

file_put_contents('out.xml', $xml);
echo "done";

The code above download the XML file with this name beginnerswebsite.wordpress.2017-08-17 and when I open the file I saw that no XML data is there instead of the XML data it has downloaded the full HTML source code of the post.

Example code 2:

function c3m_export_xml() {
    $ob_file = fopen('server_path_to_my_file.xml','w');

        'content' => 'posts',
        'start_date' => 'August 2017',
        'status' => 'published');

        function ob_file_callback($buffer)
          global $ob_file;




Same Problem as above:

  • 2
    You don't want to use a plugin, but you are pretty much asking someone to build one for you. You will get better answers here if you show the work you have done, and the issues you are having. What errors are you getting? What part of the problem are you stuck with?
    – gdaniel
    Commented Aug 17, 2017 at 14:15
  • @gdaniel I am not asking to build for me. I thought that you guys will see the link and suggest me. Sorry I have not mentioned the problems. Currently, I am updating my question. Commented Aug 17, 2017 at 14:19
  • @gdaniel Updated my question please have a look. Commented Aug 17, 2017 at 14:30
  • codex.wordpress.org/Tools_Export_Screen Commented Aug 17, 2017 at 18:39


Your Answer

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

Browse other questions tagged or ask your own question.