Export only a Subset of Wordpress pages


In the process of splitting one existing Wordpress site (comprised mostly of hierarchically arranged Pages, not posts) I needed to export a batch of pages into the new one. Here's how to modify your wp-admin/includes/export.php to do that.

First we find the ID number of the parent page that we want to export. This process will export that page and all its sub-pages (children), sub-sub-pages, etc. You can find this by hovering over the "Edit" link in the Wordpress "Pages/Edit" area and noting the "&post=number" section. In my case it was "2" -- that's the number we will use below.

In wp-admin/includes/export.php, find the lines:

// grab a snapshot of post IDs, just in case it changes during the export
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");

Comment that out, and replace with:

# Export only a particular page and all its children
$post_ids = array();
$new_pages = array();
$new_pages[] = 2; # Parent page ID, which we will export, along with all its children
while (count($new_pages)) {
  $where = "WHERE post_parent IN (".join(',', $new_pages).")";
  foreach ($new_pages as $np) {
    $post_ids[] = $np;
  $new_pages = array();
  $new_pages = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
# $post_ids array now contains the pages we wish to export

Simply run the Export process and you will have just those pages.