Skip to content

Instantly share code, notes, and snippets.

@janbiasi
Created September 9, 2014 07:52
Show Gist options
  • Save janbiasi/fd6a3ce26097488a6180 to your computer and use it in GitHub Desktop.
Save janbiasi/fd6a3ce26097488a6180 to your computer and use it in GitHub Desktop.
A simple Wordpress post exporter written in PHP
<?php
// Security checking
define('ABSPATH') or die ("Script kiddies!");
// Defining path and filename
$outPath = 'postbackup/';
$fileName = 'wp_posts_' . date('m-d-Y-His A e') . '.xml';
// Indlude the wordpress stuff
require(dirname(dirname(__FILE__)) . '/wp-load.php');
require(ABSPATH . 'wp-admin/includes/admin.php');
require('includes/export.php');
// Handle data
ob_start();
export_wp();
$xml = ob_get_clean();
// Write to the file in path configured above
file_put_contents($outPath . $fileName, $xml);
// Redirect to the root page
header('Location: http://' . $_SERVER['HTTP_HOST']);
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment