Export WordPress posts into smaller XML files

Exporting data from and old site into a new site is something that you will have to do someday. WordPress has an export tool that creates an XML file that can be used to import the old posts into the new site.

There is two option to export the posts “all content” or by content type, if you choose the content type option, the export will not include any attachment or taxonomy associated with the posts.

 

To keep all the data relationship — attachments and taxonomy— the data needs to be exported using the “all content” option, but this file can be really big and some hosting services might not allow you to upload this file. Other problem that you might experience is out or memory errors while trying to import the data.

The solution is to export the data in smaller files, for that there are a few hidden values that can used to filter the content. Use the list below to filter the content by creating a URL similar to this one:

/wp-admin/export.php?cat=0&post_author=0&post_start_date=2010-01-01&post_end_date=2010-02-15&post_status=0&page_author=0&page_status=0

Query string

  • cat: category id
  • content: “all” | “posts” | post type
  • taxonomy: “all” | taxonomy
  • post_status: status
  • post_start_date: date (YYYY-MM-DD)
  • post_end_date: date (YYYY-MM-DD)
  • page_status: status (page only)
  • post_author: user id

 Small hack for posts / attachments

if you want to include all the post attachments and categories you need to modify the wp-admin/includes/wp-import.php, once you complete the export you can change the file back. (line 48)

$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );

to

$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN( %s, 'attachment' )", $args['content'] );

 

That is it, if you have any question on problems please leave a comment we will be glad to help.