0

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?

UPDATED:

Example code 1:

require(dirname(dirname(__FILE__)) . '/wp-load.php');
require(ABSPATH . 'wp-admin/includes/admin.php');
require('includes/export.php');
require_once( ABSPATH . 'wp-admin/includes/export.php' );
ob_start();
export_wp();
$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');

    $args=array(
        'content' => 'posts',
        'start_date' => 'August 2017',
        'status' => 'published');

        function ob_file_callback($buffer)
        {
          global $ob_file;
          fwrite($ob_file,$buffer);
        }

    ob_start('ob_file_callback');
    export_wp($args);

    ob_end_flush();
}

c3m_export_xml();

Same Problem as above:

4
  • 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

0

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.