WordPress.org

Make WordPress Core

Ticket #4589: export-query-loop-r5782.patch

File export-query-loop-r5782.patch, 1.7 KB (added by tellyworth, 8 years ago)
  • wp-admin/export.php

     
    4545<?php 
    4646 
    4747function export_wp() { 
    48 global $wpdb, $posts, $post; 
     48global $wpdb, $post_ids, $post; 
    4949 
    5050$filename = 'wordpress.' . date('Y-m-d') . '.xml'; 
    5151 
     
    5959        $where = " WHERE post_author = '$author_id' "; 
    6060} 
    6161 
    62 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
     62// grab a snapshot of post IDs, just in case it changes during the export 
     63$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
    6364 
    6465$categories = (array) get_categories('get=all'); 
    6566 
     
    166167        <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category> 
    167168<?php endforeach; endif; ?> 
    168169        <?php do_action('rss2_head'); ?> 
    169         <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?> 
     170        <?php if ($post_ids) { 
     171                // fetch 20 posts at a time rather than loading the entire table into memory 
     172                while ( $next_posts = array_splice($post_ids, 0, 20) ) { 
     173                        $where = "WHERE ID IN (".join(',', $next_posts).")"; 
     174                        $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
     175                                foreach ($posts as $post) {  
     176                        start_wp(); ?> 
    170177<item> 
    171178<title><?php the_title_rss() ?></title> 
    172179<link><?php permalink_single_rss() ?></link> 
     
    216223</wp:comment> 
    217224<?php } } ?> 
    218225        </item> 
    219 <?php } } ?> 
     226<?php } } } ?> 
    220227</channel> 
    221228</rss> 
    222229<?php