Skip to main content
added 1209 characters in body
Source Link
Owaiz Yusufi
  • 502
  • 1
  • 5
  • 19

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:

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?

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:

Source Link
Owaiz Yusufi
  • 502
  • 1
  • 5
  • 19

How can I export data without using any import/export plugin

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?