diff --git a/src/wp-admin/includes/export.php b/src/wp-admin/includes/export.php
index 1c03e10..74ce5b4 100644
--- a/src/wp-admin/includes/export.php
+++ b/src/wp-admin/includes/export.php
@@ -42,52 +42,101 @@ function export_wp( $args = array() ) {
 	 */
 	do_action( 'export_wp', $args );
 
+	// Set export file name
 	$sitename = sanitize_key( get_bloginfo( 'name' ) );
 	if ( ! empty($sitename) ) $sitename .= '.';
 	$filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
 
+	// Set content headers
 	header( 'Content-Description: File Transfer' );
 	header( 'Content-Disposition: attachment; filename=' . $filename );
 	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
 
-	if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
-		$ptype = get_post_type_object( $args['content'] );
-		if ( ! $ptype->can_export )
-			$args['content'] = 'post';
+	$query_args = array(
+		'post_status' => 'any',
+		'posts_per_page' => -1
+	);
+
+	if ( 'all' != $args['content'] ) {
+		$post_types = (array) $args['content'];
+
+		$query_args['post_type'] = array();
+
+		foreach( $post_types as $post_type ) {
+			$post_type_object = get_post_type_object( $post_type );
+
+			if ( $post_type_object && $post_type_object->can_export ) {
+				$query_args['post_type'][] = $post_type;
+			}
+		}
 
-		$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
+		if ( empty( $query_args['post_type'] ) ) {
+			$query_args['post_type'] = 'post';
+		}
 	} else {
-		$post_types = get_post_types( array( 'can_export' => true ) );
-		$esses = array_fill( 0, count($post_types), '%s' );
-		$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
+		$query_args['post_type'] = array_values( get_post_types( array( 'can_export' => true ) ) );
 	}
 
-	if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) )
-		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] );
-	else
-		$where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
+	if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) {
+		$query_args['post_status'] = $args['status'];
+	}
 
-	$join = '';
 	if ( $args['category'] && 'post' == $args['content'] ) {
 		if ( $term = term_exists( $args['category'], 'category' ) ) {
-			$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
-			$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
+			$query_args['tax_query'] = array(
+				array(
+					'taxonomy' => 'category',
+					'terms' => $term->term_id,
+					'include_children' => false
+				)
+			);
 		}
 	}
 
 	if ( 'post' == $args['content'] || 'page' == $args['content'] ) {
 		if ( $args['author'] )
-			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
+			$query_args['author'] = (int) $args['author'];
+
+		$date_query = array();
 
 		if ( $args['start_date'] )
-			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
+			$date_query[]['after'] = $args['start_date'];
+
+		if ( $args['end_date'] ) {
+			$date_query[]['before'] =  '@' . strtotime( '+1 month', strtotime( $args['end_date'] ) );
+		}
 
-		if ( $args['end_date'] )
-			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) );
+		if ( ! empty( $date_query ) ) {
+			$query_args['date_query'] = $date_query;
+		}
 	}
 
-	// Grab a snapshot of post IDs, just in case it changes during the export.
-	$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
+	/**
+	 * Filter WP_Query arguments for which posts to export.
+	 *
+	 * @todo Update since
+	 * @since 4.X
+	 *
+	 * @param array $query_args An array of WP_Query arguments.
+	 * @param array $args An array of export arguments.
+	 */
+	$query_args = apply_filters( 'export_wp_query_args', $query_args, $args );
+
+	$query_args['fields'] = 'ids';
+
+	$post_ids = get_posts( $query_args );
+
+	/**
+	 * Filter Post IDs to be exported.
+	 *
+	 * @todo Update since
+	 * @since 4.X
+	 *
+	 * @param array $post_ids An array of Post IDs to export.
+	 * @param array $query_args An array of WP_Query arguments.
+	 * @param array $args An array of export arguments.
+	 */
+	$post_ids = apply_filters( 'export_wp_post_ids', $post_ids, $query_args, $args );
 
 	/*
 	 * Get the requested terms ready, empty unless posts filtered by category
@@ -98,29 +147,36 @@ function export_wp( $args = array() ) {
 		$cat = get_term( $term['term_id'], 'category' );
 		$cats = array( $cat->term_id => $cat );
 		unset( $term, $cat );
-	} elseif ( 'all' == $args['content'] ) {
+	} else if ( 'all' == $args['content'] ) {
 		$categories = (array) get_categories( array( 'get' => 'all' ) );
 		$tags = (array) get_tags( array( 'get' => 'all' ) );
 
 		$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
 		$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
 
-		// Put categories in order with no child going before its parent.
-		while ( $cat = array_shift( $categories ) ) {
-			if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
-				$cats[$cat->term_id] = $cat;
-			else
-				$categories[] = $cat;
+		// Put categories in order with no child going before its parent
+		if( $categories ) {
+			while ( $cat = array_shift( $categories ) ) {
+				if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) {
+					$cats[$cat->term_id] = $cat;
+				} else {
+					$categories[] = $cat;
+				}
+			}
 		}
 
-		// Put terms in order with no child going before its parent.
-		while ( $t = array_shift( $custom_terms ) ) {
-			if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
-				$terms[$t->term_id] = $t;
-			else
-				$custom_terms[] = $t;
+		// Put terms in order with no child going before its parent
+		if( $custom_terms ) {
+			while ( $t = array_shift( $custom_terms ) ) {
+				if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) {
+					$terms[$t->term_id] = $t;
+				} else {
+					$custom_terms[] = $t;
+				}
+			}
 		}
 
+		// Clean up
 		unset( $categories, $custom_taxonomies, $custom_terms );
 	}
 
@@ -385,24 +441,27 @@ function export_wp( $args = array() ) {
 	do_action( 'rss2_head' );
 	?>
 
-<?php if ( $post_ids ) {
-	/**
-	 * @global WP_Query $wp_query
-	 */
-	global $wp_query;
-
-	// Fake being in the loop.
-	$wp_query->in_the_loop = true;
-
-	// Fetch 20 posts at a time rather than loading the entire table into memory.
-	while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
-	$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
-	$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
-
-	// Begin Loop.
-	foreach ( $posts as $post ) {
-		setup_postdata( $post );
-		$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
+	<?php
+  	if ( $post_ids ) {
+  		$posts_per_page = 20;
+
+  		$wp_query_args = array(
+  			'post_type'      => 'any',
+  			'post_status'    => 'any',
+  			'posts_per_page' => $posts_per_page,
+  			'post__in'       => array_slice( $post_ids, 0, $posts_per_page )
+  		);
+
+  		$query = new WP_Query( $wp_query_args );
+
+  		$page = 0;
+
+  		// Paginate posts 20 at a time
+  		while ( $query->have_posts() ) {
+  			// Begin Loop.
+  			while ( $query->have_posts() ) {
+  				$query->the_post();
+					$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
 ?>
 	<item>
 		<title><?php
@@ -516,9 +575,17 @@ function export_wp( $args = array() ) {
 <?php	endforeach; ?>
 	</item>
 <?php
+			}
+
+			// Fetch next set of posts
+			$wp_query_args['post__in'] = array_slice( $post_ids, ( $page * $posts_per_page ), $posts_per_page );
+
+			$query->query( $wp_query_args );
+
+			$page++;
+		}
 	}
-	}
-} ?>
+?>
 </channel>
 </rss>
 <?php
