Taking control of Wordpress’ xml export

I’ve been working on a plugin that uses the custom fields (post meta) to hold settings and content. To transfer the settings of the plugin from the development server to the live server (yes, we’re skipping staging, hoping to set one up soon), I thought the simplest way was to create a Wordpress xml export file, for this one post, accessible via one simple link click.

The link to the xml file looks like this (btw, the plugin is called ADMinister, which is a plugin to handle advertising, and other temproary content, not related to specific pages or posts):

<a href="<?php echo get_option('siteurl'); ?> /wp-admin/export.php?download=true&administer=true">
Download</a> Worpress xml export for one post.

And in the plugin, the following bit of code will alter the export process to only export the specified ID or IDs.

function p2m_export_administer () {
   global $post_ids;
   if ($_GET['administer'])
      $post_ids = array(get_option('p2m_ad_post_id'));
}
add_action('rss2_head', 'p2m_export_administer');

The id of the page/post is held in the option ‘p2m_ad_post_id’, and the url parameter ‘administer’ is used to signify that we want to later the behaviour of the export. The global parameter $post_ids is the array that holds the ID of what to export. Even though we’re intent on only exporting one, the parameter must remain an array.

The xml file can then be imported into another Wordpress installation. Obviously, this is rather inflexible if you want to transfer settings back and forth, but the point here is to illustrate how to better control the Wordpress xml export file.

Tags: ,

2 Comments to “Taking control of Wordpress’ xml export”

  1. Captsee Says:

    The export is mainly useful for moving content between WordPress
    blogs that you run, whether it’s moving from your self-hosted blog to
    the convienence of WordPress.com or the other direction. It includes
    posts, pages, comments, drafts, private posts, categories, and more.
    We don’t yet have a plugin that can generate this format for older
    version of WP, but it’ll be coming soon and when it’s done we’ll post
    about it.

  2. cheent Says:

    Занимаюсь дизайном и хочу попросить автора labs.dagensskiva.com отправить шаьлончик на мой мыил) Готов заплатить…

Leave a Reply