<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[14444] trunk/wp-admin: export improvements, props blepoxp, see #10317</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14444">14444</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-05-04 17:31:36 +0000 (Tue, 04 May 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>export improvements, props blepoxp, see <a href="http://trac.wordpress.org/ticket/10317">#10317</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminexportphp">trunk/wp-admin/export.php</a></li>
<li><a href="#trunkwpadminincludesexportphp">trunk/wp-admin/includes/export.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminexportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/export.php (14443 => 14444)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/export.php        2010-05-04 17:13:11 UTC (rev 14443)
+++ trunk/wp-admin/export.php        2010-05-04 17:31:36 UTC (rev 14444)
</span><span class="lines">@@ -18,41 +18,39 @@
</span><span class="cx"> 
</span><span class="cx"> if ( isset( $_GET['download'] ) ) {
</span><span class="cx">                 $author = isset($_GET['author']) ? $_GET['author'] : 'all';
</span><del>-                $category = isset($_GET['category']) ? $_GET['category'] : 'all';
</del><ins>+                $taxonomy = array();
+                foreach ( get_taxonomies( array( 'show_ui' =&gt; true ) ) as $tax )
+                        $taxonomy[ $tax ] = ! empty( $_GET['taxonomy'][ $tax ] ) ? $_GET['taxonomy'][ $tax ] : 'all';
</ins><span class="cx">                 $post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all';
</span><span class="cx">                 $status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all';
</span><span class="cx">                 $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all';
</span><span class="cx">                 $mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all';
</span><del>-                $aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0;
-                $aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0;
-                if($mm_start != 'all' &amp;&amp; $aa_start &gt; 0) {
-                        $start_date = sprintf( &quot;%04d-%02d-%02d&quot;, $aa_start, $mm_start, 1 );
</del><ins>+                if( $mm_start != 'all' ) {
+                        $start_date = sprintf( &quot;%04d-%02d-%02d&quot;, substr( $mm_start, 0, 4 ), substr( $mm_start, 5, 2 ), 1 );
</ins><span class="cx">                 } else {
</span><span class="cx">                         $start_date = 'all';
</span><span class="cx">                 }
</span><del>-                if($mm_end != 'all' &amp;&amp; $aa_end &gt; 0) {
-                        if($mm_end == 12) {
-                                $mm_end = 1;
-                                $aa_end++;
-                        } else {
-                                $mm_end++;
-                        }
-                        $end_date = sprintf( &quot;%04d-%02d-%02d&quot;, $aa_end, $mm_end, 1 );
</del><ins>+                if( $mm_end != 'all' ) {
+                        $end_date = sprintf( &quot;%04d-%02d-%02d&quot;, substr( $mm_end, 0, 4 ), substr( $mm_end, 5, 2 ), 1 );
</ins><span class="cx">                 } else {
</span><span class="cx">                         $end_date = 'all';
</span><span class="cx">                 }
</span><del>-        export_wp( $author, $category, $post_type, $status, $start_date, $end_date );
</del><ins>+
+        export_wp( array( 'author' =&gt; $author, 'taxonomy' =&gt; $taxonomy, 'post_type' =&gt; $post_type, 'post_status' =&gt; $status, 'start_date' =&gt; $start_date, 'end_date' =&gt; $end_date ) );
</ins><span class="cx">         die();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> require_once ('admin-header.php');
</span><span class="cx"> 
</span><del>-$months = &quot;&quot;;
-for ( $i = 1; $i &lt; 13; $i++ ) {
-        $months .= &quot;\t\t\t&lt;option value=\&quot;&quot; . zeroise($i, 2) . '&quot;&gt;' .
-                $wp_locale-&gt;get_month_abbrev( $wp_locale-&gt;get_month( $i ) ) . &quot;&lt;/option&gt;\n&quot;;
-} ?&gt;
</del><ins>+$dateoptions = '';
+if ( $monthyears = $wpdb-&gt;get_results( &quot;SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb-&gt;posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC &quot; ) ) {
+        foreach ( $monthyears as $monthyear ) {
+                $dateoptions .= &quot;\t&lt;option value=\&quot;&quot; . $monthyear-&gt;year . '-' . zeroise( $monthyear-&gt;month, 2 ) . '&quot;&gt;' . $wp_locale-&gt;get_month( $monthyear-&gt;month ) . ' ' . $monthyear-&gt;year . &quot;&lt;/option&gt;\n&quot;;
+        }
+}
</ins><span class="cx"> 
</span><ins>+?&gt;
+
</ins><span class="cx"> &lt;div class=&quot;wrap&quot;&gt;
</span><span class="cx"> &lt;?php screen_icon(); ?&gt;
</span><span class="cx"> &lt;h2&gt;&lt;?php echo esc_html( $title ); ?&gt;&lt;/h2&gt;
</span><span class="lines">@@ -66,19 +64,16 @@
</span><span class="cx"> &lt;table class=&quot;form-table&quot;&gt;
</span><span class="cx"> &lt;tr&gt;
</span><span class="cx"> &lt;th&gt;&lt;label for=&quot;mm_start&quot;&gt;&lt;?php _e('Restrict Date'); ?&gt;&lt;/label&gt;&lt;/th&gt;
</span><del>-&lt;td&gt;&lt;strong&gt;&lt;?php _e('Start:'); ?&gt;&lt;/strong&gt; &lt;?php _e('Month'); ?&gt;&amp;nbsp;
</del><ins>+&lt;td&gt;&lt;strong&gt;&lt;?php _e('Start:'); ?&gt;&lt;/strong&gt; 
</ins><span class="cx"> &lt;select name=&quot;mm_start&quot; id=&quot;mm_start&quot;&gt;
</span><del>-&lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Dates'); ?&gt;&lt;/option&gt;
-&lt;?php echo $months; ?&gt;
-&lt;/select&gt;&amp;nbsp;&lt;?php _e('Year'); ?&gt;&amp;nbsp;
-&lt;input type=&quot;text&quot; id=&quot;aa_start&quot; name=&quot;aa_start&quot; value=&quot;&quot; size=&quot;4&quot; maxlength=&quot;5&quot; /&gt;
-&lt;/td&gt;
-&lt;td&gt;&lt;strong&gt;&lt;?php _e('End:'); ?&gt;&lt;/strong&gt; &lt;?php _e('Month'); ?&gt;&amp;nbsp;
</del><ins>+        &lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Dates'); ?&gt;&lt;/option&gt;
+&lt;?php echo ($dateoptions); ?&gt;
+&lt;/select&gt; &lt;br/&gt;
+&lt;strong&gt;&lt;?php _e('End:'); ?&gt;&lt;/strong&gt; 
</ins><span class="cx"> &lt;select name=&quot;mm_end&quot; id=&quot;mm_end&quot;&gt;
</span><del>-&lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Dates'); ?&gt;&lt;/option&gt;
-&lt;?php echo $months; ?&gt;
-&lt;/select&gt;&amp;nbsp;&lt;?php _e('Year'); ?&gt;&amp;nbsp;
-&lt;input type=&quot;text&quot; id=&quot;aa_end&quot; name=&quot;aa_end&quot; value=&quot;&quot; size=&quot;4&quot; maxlength=&quot;5&quot; /&gt;
</del><ins>+        &lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Dates'); ?&gt;&lt;/option&gt;
+&lt;?php echo $dateoptions; ?&gt;
+&lt;/select&gt;
</ins><span class="cx"> &lt;/td&gt;
</span><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> &lt;tr&gt;
</span><span class="lines">@@ -87,36 +82,33 @@
</span><span class="cx"> &lt;select name=&quot;author&quot; id=&quot;author&quot;&gt;
</span><span class="cx"> &lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Authors'); ?&gt;&lt;/option&gt;
</span><span class="cx"> &lt;?php
</span><del>-$authors = $wpdb-&gt;get_results( &quot;SELECT DISTINCT u.id, u.display_name FROM $wpdb-&gt;users u INNER JOIN $wpdb-&gt;posts p ON u.id = p.post_author ORDER BY u.display_name&quot; );
-foreach ( (array) $authors as $author )
-       echo &quot;&lt;option value='{$author-&gt;id}'&gt;{$author-&gt;display_name}&lt;/option&gt;\n&quot;;
</del><ins>+$authors = $wpdb-&gt;get_results( &quot;SELECT DISTINCT u.id, u.display_name FROM $wpdb-&gt;users u INNER JOIN $wpdb-&gt;posts p WHERE u.id = p.post_author ORDER BY u.display_name&quot; );
+foreach ( (array) $authors as $author ) {
+        echo &quot;&lt;option value='{$author-&gt;id}'&gt;{$author-&gt;display_name}&lt;/option&gt;\n&quot;;
+}
</ins><span class="cx"> ?&gt;
</span><span class="cx"> &lt;/select&gt;
</span><span class="cx"> &lt;/td&gt;
</span><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> &lt;tr&gt;
</span><del>-&lt;th&gt;&lt;label for=&quot;category&quot;&gt;&lt;?php _e('Restrict Category'); ?&gt;&lt;/label&gt;&lt;/th&gt;
</del><ins>+&lt;th&gt;&lt;?php _e('Restrict Taxonomies'); ?&gt;&lt;/th&gt;
</ins><span class="cx"> &lt;td&gt;
</span><del>-&lt;select name=&quot;category&quot; id=&quot;category&quot;&gt;
-&lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Categories'); ?&gt;&lt;/option&gt;
-&lt;?php
-$categories = (array) get_categories('get=all');
-if($categories) {
-        foreach ( $categories as $cat ) {
-                echo &quot;&lt;option value='{$cat-&gt;term_taxonomy_id}'&gt;{$cat-&gt;name}&lt;/option&gt;\n&quot;;
-        }
</del><ins>+&lt;?php foreach ( get_taxonomies( array( 'show_ui' =&gt; true ), 'objects' ) as $tax_obj ) {
+        $term_dropdown = wp_dropdown_categories( array( 'taxonomy' =&gt; $tax_obj-&gt;name, 'hide_if_empty' =&gt; true, 'show_option_all' =&gt; __( 'All Terms' ), 'name' =&gt; 'taxonomy[' . $tax_obj-&gt;name . ']', 'id' =&gt; 'taxonomy-' . $tax_obj-&gt;name, 'class' =&gt; '', 'echo' =&gt; false ) );
+        if ( $term_dropdown )
+                echo '&lt;label for=&quot;taxonomy-' . $tax_obj-&gt;name . '&quot;&gt;' . $tax_obj-&gt;label . '&lt;/label&gt;: ' . $term_dropdown . '&lt;br/&gt;';
</ins><span class="cx"> }
</span><span class="cx"> ?&gt;
</span><del>-&lt;/select&gt;
</del><span class="cx"> &lt;/td&gt;
</span><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> &lt;tr&gt;
</span><span class="cx"> &lt;th&gt;&lt;label for=&quot;post_type&quot;&gt;&lt;?php _e('Restrict Content'); ?&gt;&lt;/label&gt;&lt;/th&gt;
</span><span class="cx"> &lt;td&gt;
</span><span class="cx"> &lt;select name=&quot;post_type&quot; id=&quot;post_type&quot;&gt;
</span><del>-&lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Content'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;page&quot;&gt;&lt;?php _e('Pages'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;post&quot;&gt;&lt;?php _e('Posts'); ?&gt;&lt;/option&gt;
</del><ins>+        &lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Content'); ?&gt;&lt;/option&gt;
+        &lt;?php foreach ( get_post_types( array( 'public' =&gt; true, 'can_export' =&gt; true ), 'objects' ) as $post_type_obj ) { ?&gt;
+                &lt;option value=&quot;&lt;?php echo $post_type_obj-&gt;name; ?&gt;&quot;&gt;&lt;?php echo $post_type_obj-&gt;label; ?&gt;&lt;/option&gt;
+        &lt;?php } ?&gt;
</ins><span class="cx"> &lt;/select&gt;
</span><span class="cx"> &lt;/td&gt;
</span><span class="cx"> &lt;/tr&gt;
</span><span class="lines">@@ -124,11 +116,10 @@
</span><span class="cx"> &lt;th&gt;&lt;label for=&quot;status&quot;&gt;&lt;?php _e('Restrict Status'); ?&gt;&lt;/label&gt;&lt;/th&gt;
</span><span class="cx"> &lt;td&gt;
</span><span class="cx"> &lt;select name=&quot;status&quot; id=&quot;status&quot;&gt;
</span><del>-&lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Statuses'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;draft&quot;&gt;&lt;?php _e('Draft'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;private&quot;&gt;&lt;?php _e('Privately published'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;publish&quot;&gt;&lt;?php _e('Published'); ?&gt;&lt;/option&gt;
-&lt;option value=&quot;future&quot;&gt;&lt;?php _e('Scheduled'); ?&gt;&lt;/option&gt;
</del><ins>+        &lt;option value=&quot;all&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('All Statuses'); ?&gt;&lt;/option&gt;
+&lt;?php foreach ( get_post_stati( array( 'internal' =&gt; false ), 'objects' ) as $post_status_obj ) { ?&gt;
+        &lt;option value=&quot;&lt;?php echo $post_status_obj-&gt;name; ?&gt;&quot;&gt;&lt;?php echo $post_status_obj-&gt;label; ?&gt;&lt;/option&gt;
+&lt;?php } ?&gt;
</ins><span class="cx"> &lt;/select&gt;
</span><span class="cx"> &lt;/td&gt;
</span><span class="cx"> &lt;/tr&gt;
</span></span></pre></div>
<a id="trunkwpadminincludesexportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/export.php (14443 => 14444)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/export.php        2010-05-04 17:13:11 UTC (rev 14443)
+++ trunk/wp-admin/includes/export.php        2010-05-04 17:31:36 UTC (rev 14444)
</span><span class="lines">@@ -21,253 +21,260 @@
</span><span class="cx">  *
</span><span class="cx">  * @since unknown
</span><span class="cx">  *
</span><del>- * @param unknown_type $author
</del><ins>+ * @param unknown_type $args
</ins><span class="cx">  */
</span><del>-function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
-global $wpdb, $post_ids, $post, $wp_taxonomies;
-
-do_action('export_wp');
-
-if(strlen($start_date) &gt; 4 &amp;&amp; strlen($end_date) &gt; 4) {
-        $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
-} else {
-        $filename = 'wordpress.' . date('Y-m-d') . '.xml';
-}
-
-header('Content-Description: File Transfer');
-header(&quot;Content-Disposition: attachment; filename=$filename&quot;);
-header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
-
-if ( $post_type and $post_type != 'all' ) {
</del><ins>+function export_wp( $args = array() ) {
+        global $wpdb, $post_ids, $post, $wp_taxonomies;
+        
+        if ( ! is_array( $args ) )
+                $args = array( 'author' =&gt; $args );
+        
+        $defaults = array( 'author' =&gt; null, 'taxonomy' =&gt; null, 'post_type' =&gt; null, 'post_status' =&gt; null, 'start_date' =&gt; null, 'end_date' =&gt; null );
+        $args = wp_parse_args( $args, $defaults );
+        
+        extract($args);
+        
+        do_action('export_wp');
+        
+        if( strlen( $start_date ) &gt; 4 &amp;&amp; strlen( $end_date ) &gt; 4 )
+                $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
+        else
+                $filename = 'wordpress.' . date( 'Y-m-d' ) . '.xml';
+        
+        header( 'Content-Description: File Transfer' );
+        header( 'Content-Disposition: attachment; filename=' . $filename );
+        header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
+        
+        if ( $post_type &amp;&amp; $post_type != 'all' )
</ins><span class="cx">                 $where = $wpdb-&gt;prepare(&quot;WHERE post_type = %s &quot;, $post_type);
</span><del>-} else {
</del><ins>+        else
</ins><span class="cx">                 $where = &quot;WHERE post_type != 'revision' &quot;;
</span><del>-}
-if ( $author and $author != 'all' ) {
</del><ins>+        
+        if ( $author &amp;&amp; $author != 'all' ) {
</ins><span class="cx">                 $author_id = (int) $author;
</span><del>-                $where .= $wpdb-&gt;prepare(&quot;AND post_author = %d &quot;, $author_id);
-}
-if ( $start_date and $start_date != 'all' ) {
-                $where .= $wpdb-&gt;prepare(&quot;AND post_date &gt;= %s &quot;, $start_date);
-}
-if ( $end_date and $end_date != 'all' ) {
-                $where .= $wpdb-&gt;prepare(&quot;AND post_date &lt; %s &quot;, $end_date);
-}
-if ( $category and $category != 'all' ) {
-                $taxomony_id = (int) $category;
-                $where .= $wpdb-&gt;prepare(&quot;AND ID IN (SELECT object_id FROM {$wpdb-&gt;term_relationships} &quot; . &quot;WHERE term_taxonomy_id = %d) &quot;, $taxomony_id);
-}
-if ( $status and $status != 'all' ) {
-                $where .= $wpdb-&gt;prepare(&quot;AND post_status = %s &quot;, $status);
-}
-
-// grab a snapshot of post IDs, just in case it changes during the export
-$post_ids = $wpdb-&gt;get_col(&quot;SELECT ID FROM $wpdb-&gt;posts $where ORDER BY post_date_gmt ASC&quot;);
-
-$categories = (array) get_categories(array('get' =&gt; 'all'));
-$tags = (array) get_tags(array('get' =&gt; 'all'));
-
-$custom_taxonomies = $wp_taxonomies;
-unset($custom_taxonomies['category']);
-unset($custom_taxonomies['post_tag']);
-unset($custom_taxonomies['link_category']);
-$custom_taxonomies = array_keys($custom_taxonomies);
-$terms = (array) get_terms($custom_taxonomies, array('get' =&gt; 'all'));
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param unknown_type $categories
- */
-function wxr_missing_parents($categories) {
-        if ( !is_array($categories) || empty($categories) )
-                return array();
-
-        foreach ( $categories as $category )
-                $parents[$category-&gt;term_id] = $category-&gt;parent;
-
-        $parents = array_unique(array_diff($parents, array_keys($parents)));
-
-        if ( $zero = array_search('0', $parents) )
-                unset($parents[$zero]);
-
-        return $parents;
-}
-
-while ( $parents = wxr_missing_parents($categories) ) {
-        $found_parents = get_categories(array('include' =&gt; join(', ', $parents)));
-        if ( is_array($found_parents) &amp;&amp; count($found_parents) )
-                $categories = array_merge($categories, $found_parents);
-        else
-                break;
-}
-
-// Put them in order to be inserted with no child going before its parent
-$pass = 0;
-$passes = 1000 + count($categories);
-while ( ( $cat = array_shift($categories) ) &amp;&amp; ++$pass &lt; $passes ) {
-        if ( $cat-&gt;parent == 0 || isset($cats[$cat-&gt;parent]) ) {
-                $cats[$cat-&gt;term_id] = $cat;
-        } else {
-                $categories[] = $cat;
</del><ins>+                $where .= $wpdb-&gt;prepare( &quot;AND post_author = %d &quot;, $author_id );
</ins><span class="cx">         }
</span><del>-}
-unset($categories);
-
-/**
- * Place string in CDATA tag.
- *
- * @since unknown
- *
- * @param string $str String to place in XML CDATA tag.
- */
-function wxr_cdata($str) {
-        if ( seems_utf8($str) == false )
-                $str = utf8_encode($str);
-
-        // $str = ent2ncr(esc_html($str));
-
-        $str = &quot;&lt;![CDATA[$str&quot; . ( ( substr($str, -1) == ']' ) ? ' ' : '') . &quot;]]&gt;&quot;;
-
-        return $str;
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @return string Site URL.
- */
-function wxr_site_url() {
-        global $current_site;
-
-        // mu: the base url
-        if ( isset($current_site-&gt;domain) ) {
-                return 'http://'.$current_site-&gt;domain.$current_site-&gt;path;
</del><ins>+        
+        if ( $start_date &amp;&amp; $start_date != 'all' )
+                $where .= $wpdb-&gt;prepare( &quot;AND post_date &gt;= %s &quot;, $start_date );
+        
+        if ( $end_date &amp;&amp; $end_date != 'all' )
+                $where .= $wpdb-&gt;prepare( &quot;AND post_date &lt; %s &quot;, $end_date );
+        
+        if ( $taxonomy &amp;&amp; is_array( $taxonomy ) ) {
+                foreach ( $taxonomy as $term_id ) {
+                        if ( $term_id != 'all' )
+                                $where .= $wpdb-&gt;prepare( &quot;AND ID IN (SELECT object_id FROM $wpdb-&gt;term_relationships WHERE term_taxonomy_id = %d) &quot;, $term_id );
+                }
</ins><span class="cx">         }
</span><del>-        // wp: the blog url
-        else {
-                return get_bloginfo_rss('url');
</del><ins>+        
+        if ( $post_status &amp;&amp; $post_status != 'all' )
+                $where .= $wpdb-&gt;prepare( &quot;AND post_status = %s&quot;, $status );
+        
+        // grab a snapshot of post IDs, just in case it changes during the export
+        $post_ids = $wpdb-&gt;get_col( &quot;SELECT ID FROM $wpdb-&gt;posts $where ORDER BY post_date_gmt ASC&quot; );
+        
+        $categories = (array) get_categories( array( 'get' =&gt; 'all' ) );
+        $tags = (array) get_tags( array( 'get' =&gt; 'all' ) );
+        
+        $custom_taxonomies = $wp_taxonomies;
+        unset( $custom_taxonomies['category'] );
+        unset( $custom_taxonomies['post_tag'] );
+        unset( $custom_taxonomies['link_category'] );
+        $custom_taxonomies = array_keys( $custom_taxonomies );
+        $terms = (array) get_terms( $custom_taxonomies, array( 'get' =&gt; 'all' ) );
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param unknown_type $categories
+         */
+        function wxr_missing_parents( $categories ) {
+                if ( ! is_array( $categories ) || empty( $categories ) )
+                        return array();
+        
+                foreach ( $categories as $category ){
+                        $parents[$category-&gt;term_id] = $category-&gt;parent;
+                }
+        
+                $parents = array_unique( array_diff( $parents, array_keys( $parents ) ) );
+        
+                if ( $zero = array_search( '0', $parents ) )
+                        unset( $parents[$zero] );
+        
+                return $parents;
</ins><span class="cx">         }
</span><del>-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $c Category Object
- */
-function wxr_cat_name($c) {
-        if ( empty($c-&gt;name) )
-                return;
-
-        echo '&lt;wp:cat_name&gt;' . wxr_cdata($c-&gt;name) . '&lt;/wp:cat_name&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $c Category Object
- */
-function wxr_category_description($c) {
-        if ( empty($c-&gt;description) )
-                return;
-
-        echo '&lt;wp:category_description&gt;' . wxr_cdata($c-&gt;description) . '&lt;/wp:category_description&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Tag Object
- */
-function wxr_tag_name($t) {
-        if ( empty($t-&gt;name) )
-                return;
-
-        echo '&lt;wp:tag_name&gt;' . wxr_cdata($t-&gt;name) . '&lt;/wp:tag_name&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Tag Object
- */
-function wxr_tag_description($t) {
-        if ( empty($t-&gt;description) )
-                return;
-
-        echo '&lt;wp:tag_description&gt;' . wxr_cdata($t-&gt;description) . '&lt;/wp:tag_description&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Term Object
- */
-function wxr_term_name($t) {
-        if ( empty($t-&gt;name) )
-                return;
-
-        echo '&lt;wp:term_name&gt;' . wxr_cdata($t-&gt;name) . '&lt;/wp:term_name&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Term Object
- */
-function wxr_term_description($t) {
-        if ( empty($t-&gt;description) )
-                return;
-
-        echo '&lt;wp:term_description&gt;' . wxr_cdata($t-&gt;description) . '&lt;/wp:term_description&gt;';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- */
-function wxr_post_taxonomy() {
-        global $post;
-
-        $the_list = '';
-        $filter = 'rss';
-
-        $taxonomies = get_object_taxonomies('post');
-        $terms = wp_get_post_terms($post-&gt;ID, $taxonomies);
-        foreach ( (array) $terms as $term ) {
-                $domain = ( 'post_tag' == $term-&gt;taxonomy ) ? 'tag' : $term-&gt;taxonomy;
-                $term_name = sanitize_term_field('name', $term-&gt;name, $term-&gt;term_id, $term-&gt;taxonomy, $filter);
-                // Back compat.
-                if ( 'category' == $term-&gt;taxonomy )
-                        $the_list .= &quot;\n\t\t&lt;category&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
-                elseif ( 'post_tag' == $term-&gt;taxonomy )
-                        $the_list .= &quot;\n\t\t&lt;category domain=\&quot;$domain\&quot;&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
-                // forwards compatibility as above
-                $the_list .= &quot;\n\t\t&lt;category domain=\&quot;$domain\&quot; nicename=\&quot;{$term-&gt;slug}\&quot;&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
</del><ins>+        
+        while ( $parents = wxr_missing_parents( $categories ) ) {
+                $found_parents = get_categories( array( 'include' =&gt; join( ', ', $parents) ) );
+                if ( is_array( $found_parents ) &amp;&amp; count( $found_parents ) )
+                        $categories = array_merge( $categories, $found_parents );
+                else
+                        break;
</ins><span class="cx">         }
</span><del>-        echo $the_list;
-}
-
-echo '&lt;?xml version=&quot;1.0&quot; encoding=&quot;' . get_bloginfo('charset') . '&quot;?' . &quot;&gt;\n&quot;;
-
-?&gt;
</del><ins>+        
+        // Put them in order to be inserted with no child going before its parent
+        $pass = 0;
+        $passes = 1000 + count( $categories );
+        while ( ( $cat = array_shift( $categories ) ) &amp;&amp; ++$pass &lt; $passes ) {
+                if ( $cat-&gt;parent == 0 || isset( $cats[$cat-&gt;parent] ) )
+                        $cats[$cat-&gt;term_id] = $cat;
+                else
+                        $categories[] = $cat;
+        }
+        unset( $categories );
+        
+        /**
+         * Place string in CDATA tag.
+         *
+         * @since unknown
+         *
+         * @param string $str String to place in XML CDATA tag.
+         */
+        function wxr_cdata( $str ) {
+                if ( seems_utf8( $str ) == false )
+                        $str = utf8_encode( $str );
+        
+                // $str = ent2ncr(esc_html($str));
+                $str = &quot;&lt;![CDATA[$str&quot; . ( ( substr( $str, -1 ) == ']' ) ? ' ' : '') . &quot;]]&gt;&quot;;
+        
+                return $str;
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @return string Site URL.
+         */
+        function wxr_site_url() {
+                global $current_site;
+        
+                // mu: the base url
+                if ( isset( $current_site-&gt;domain ) )
+                        return 'http://' . $current_site-&gt;domain . $current_site-&gt;path;
+                // wp: the blog url
+                else
+                        return get_bloginfo_rss( 'url' );
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $c Category Object
+         */
+        function wxr_cat_name( $c ) {
+                if ( empty( $c-&gt;name ) )
+                        return;
+        
+                echo '&lt;wp:cat_name&gt;' . wxr_cdata( $c-&gt;name ) . '&lt;/wp:cat_name&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $c Category Object
+         */
+        function wxr_category_description( $c ) {
+                if ( empty( $c-&gt;description ) )
+                        return;
+        
+                echo '&lt;wp:category_description&gt;' . wxr_cdata($c-&gt;description) . '&lt;/wp:category_description&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $t Tag Object
+         */
+        function wxr_tag_name( $t ) {
+                if ( empty( $t-&gt;name ) )
+                        return;
+        
+                echo '&lt;wp:tag_name&gt;' . wxr_cdata($t-&gt;name) . '&lt;/wp:tag_name&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $t Tag Object
+         */
+        function wxr_tag_description( $t ) {
+                if ( empty( $t-&gt;description ) )
+                        return;
+        
+                echo '&lt;wp:tag_description&gt;' . wxr_cdata($t-&gt;description) . '&lt;/wp:tag_description&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $t Term Object
+         */
+        function wxr_term_name( $t ) {
+                if ( empty( $t-&gt;name ) )
+                        return;
+        
+                echo '&lt;wp:term_name&gt;' . wxr_cdata($t-&gt;name) . '&lt;/wp:term_name&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         *
+         * @param object $t Term Object
+         */
+        function wxr_term_description( $t ) {
+                if ( empty( $t-&gt;description ) )
+                        return;
+        
+                echo '&lt;wp:term_description&gt;' . wxr_cdata($t-&gt;description) . '&lt;/wp:term_description&gt;';
+        }
+        
+        /**
+         * {@internal Missing Short Description}}
+         *
+         * @since unknown
+         */
+        function wxr_post_taxonomy() {
+                global $post;
+        
+                $the_list = '';
+                $filter = 'rss';
+        
+                $taxonomies = get_object_taxonomies( 'post' );
+                $terms = wp_get_post_terms( $post-&gt;ID, $taxonomies );
+                foreach ( (array) $terms as $term ) {
+                        $domain = ( 'post_tag' == $term-&gt;taxonomy ) ? 'tag' : $term-&gt;taxonomy;
+                        $term_name = sanitize_term_field( 'name', $term-&gt;name, $term-&gt;term_id, $term-&gt;taxonomy, $filter );
+                        // Back compat.
+                        if ( 'category' == $term-&gt;taxonomy )
+                                $the_list .= &quot;\n\t\t&lt;category&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
+                        elseif ( 'post_tag' == $term-&gt;taxonomy )
+                                $the_list .= &quot;\n\t\t&lt;category domain=\&quot;$domain\&quot;&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
+                        // forwards compatibility as above
+                        $the_list .= &quot;\n\t\t&lt;category domain=\&quot;$domain\&quot; nicename=\&quot;{$term-&gt;slug}\&quot;&gt;&lt;![CDATA[$term_name]]&gt;&lt;/category&gt;\n&quot;;
+                }
+                echo $the_list;
+        }
+        
+        echo '&lt;?xml version=&quot;1.0&quot; encoding=&quot;' . get_bloginfo('charset') . '&quot;?' . &quot;&gt;\n&quot;;
+        
+        ?&gt;
</ins><span class="cx"> &lt;!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. --&gt;
</span><span class="cx"> &lt;!-- It contains information about your blog's posts, comments, and categories. --&gt;
</span><span class="cx"> &lt;!-- You may use this file to transfer that content from one site to another. --&gt;
</span><span class="lines">@@ -284,7 +291,7 @@
</span><span class="cx"> &lt;!-- 6. WordPress will then import each of the posts, comments, and categories --&gt;
</span><span class="cx"> &lt;!--    contained in this file into your blog --&gt;
</span><span class="cx"> 
</span><del>-&lt;?php the_generator('export');?&gt;
</del><ins>+&lt;?php the_generator( 'export' );?&gt;
</ins><span class="cx"> &lt;rss version=&quot;2.0&quot;
</span><span class="cx">         xmlns:excerpt=&quot;http://wordpress.org/export/&lt;?php echo WXR_VERSION; ?&gt;/excerpt/&quot;
</span><span class="cx">         xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot;
</span><span class="lines">@@ -294,98 +301,106 @@
</span><span class="cx"> &gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;channel&gt;
</span><del>-        &lt;title&gt;&lt;?php bloginfo_rss('name'); ?&gt;&lt;/title&gt;
-        &lt;link&gt;&lt;?php bloginfo_rss('url') ?&gt;&lt;/link&gt;
-        &lt;description&gt;&lt;?php bloginfo_rss(&quot;description&quot;) ?&gt;&lt;/description&gt;
-        &lt;pubDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?&gt;&lt;/pubDate&gt;
-        &lt;generator&gt;http://wordpress.org/?v=&lt;?php bloginfo_rss('version'); ?&gt;&lt;/generator&gt;
-        &lt;language&gt;&lt;?php echo get_option('rss_language'); ?&gt;&lt;/language&gt;
</del><ins>+        &lt;title&gt;&lt;?php bloginfo_rss( 'name' ); ?&gt;&lt;/title&gt;
+        &lt;link&gt;&lt;?php bloginfo_rss( 'url' ) ?&gt;&lt;/link&gt;
+        &lt;description&gt;&lt;?php bloginfo_rss( 'description' ) ?&gt;&lt;/description&gt;
+        &lt;pubDate&gt;&lt;?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ); ?&gt;&lt;/pubDate&gt;
+        &lt;generator&gt;http://wordpress.org/?v=&lt;?php bloginfo_rss( 'version' ); ?&gt;&lt;/generator&gt;
+        &lt;language&gt;&lt;?php echo get_option( 'rss_language' ); ?&gt;&lt;/language&gt;
</ins><span class="cx">         &lt;wp:wxr_version&gt;&lt;?php echo WXR_VERSION; ?&gt;&lt;/wp:wxr_version&gt;
</span><span class="cx">         &lt;wp:base_site_url&gt;&lt;?php echo wxr_site_url(); ?&gt;&lt;/wp:base_site_url&gt;
</span><del>-        &lt;wp:base_blog_url&gt;&lt;?php bloginfo_rss('url'); ?&gt;&lt;/wp:base_blog_url&gt;
-&lt;?php if ( $cats ) : foreach ( $cats as $c ) : ?&gt;
-        &lt;wp:category&gt;&lt;wp:category_nicename&gt;&lt;?php echo $c-&gt;slug; ?&gt;&lt;/wp:category_nicename&gt;&lt;wp:category_parent&gt;&lt;?php echo $c-&gt;parent ? $cats[$c-&gt;parent]-&gt;name : ''; ?&gt;&lt;/wp:category_parent&gt;&lt;?php wxr_cat_name($c); ?&gt;&lt;?php wxr_category_description($c); ?&gt;&lt;/wp:category&gt;
-&lt;?php endforeach; endif; ?&gt;
-&lt;?php if ( $tags ) : foreach ( $tags as $t ) : ?&gt;
-        &lt;wp:tag&gt;&lt;wp:tag_slug&gt;&lt;?php echo $t-&gt;slug; ?&gt;&lt;/wp:tag_slug&gt;&lt;?php wxr_tag_name($t); ?&gt;&lt;?php wxr_tag_description($t); ?&gt;&lt;/wp:tag&gt;
-&lt;?php endforeach; endif; ?&gt;
-&lt;?php if ( $terms ) : foreach ( $terms as $t ) : ?&gt;
-        &lt;wp:term&gt;&lt;wp:term_taxonomy&gt;&lt;?php echo $t-&gt;taxonomy; ?&gt;&lt;/wp:term_taxonomy&gt;&lt;wp:term_slug&gt;&lt;?php echo $t-&gt;slug; ?&gt;&lt;/wp:term_slug&gt;&lt;wp:term_parent&gt;&lt;?php echo $t-&gt;parent ? $custom_taxonomies[$t-&gt;parent]-&gt;name : ''; ?&gt;&lt;/wp:term_parent&gt;&lt;?php wxr_term_name($t); ?&gt;&lt;?php wxr_term_description($t); ?&gt;&lt;/wp:term&gt;
-&lt;?php endforeach; endif; ?&gt;
-        &lt;?php do_action('rss2_head'); ?&gt;
-        &lt;?php if ($post_ids) {
-                global $wp_query;
-                $wp_query-&gt;in_the_loop = true;  // Fake being in the loop.
-                // fetch 20 posts at a time rather than loading the entire table into memory
-                while ( $next_posts = array_splice($post_ids, 0, 20) ) {
-                        $where = &quot;WHERE ID IN (&quot;.join(',', $next_posts).&quot;)&quot;;
-                        $posts = $wpdb-&gt;get_results(&quot;SELECT * FROM $wpdb-&gt;posts $where ORDER BY post_date_gmt ASC&quot;);
-                                foreach ($posts as $post) {
-                        setup_postdata($post);
</del><ins>+        &lt;wp:base_blog_url&gt;&lt;?php bloginfo_rss( 'url' ); ?&gt;&lt;/wp:base_blog_url&gt;
+        &lt;?php if ( $cats ) : foreach ( $cats as $c ) : ?&gt;
+        &lt;wp:category&gt;&lt;wp:category_nicename&gt;&lt;?php echo $c-&gt;slug; ?&gt;&lt;/wp:category_nicename&gt;&lt;wp:category_parent&gt;&lt;?php echo $c-&gt;parent ? $cats[$c-&gt;parent]-&gt;name : ''; ?&gt;&lt;/wp:category_parent&gt;&lt;?php wxr_cat_name( $c ); ?&gt;&lt;?php wxr_category_description( $c ); ?&gt;&lt;/wp:category&gt;
+        &lt;?php endforeach; endif; ?&gt;
+        &lt;?php if ( $tags ) : foreach ( $tags as $t ) : ?&gt;
+        &lt;wp:tag&gt;&lt;wp:tag_slug&gt;&lt;?php echo $t-&gt;slug; ?&gt;&lt;/wp:tag_slug&gt;&lt;?php wxr_tag_name( $t ); ?&gt;&lt;?php wxr_tag_description( $t ); ?&gt;&lt;/wp:tag&gt;
+        &lt;?php endforeach; endif; ?&gt;
+        &lt;?php if ( $terms ) : foreach ( $terms as $t ) : ?&gt;
+        &lt;wp:term&gt;&lt;wp:term_taxonomy&gt;&lt;?php echo $t-&gt;taxonomy; ?&gt;&lt;/wp:term_taxonomy&gt;&lt;wp:term_slug&gt;&lt;?php echo $t-&gt;slug; ?&gt;&lt;/wp:term_slug&gt;&lt;wp:term_parent&gt;&lt;?php echo $t-&gt;parent ? $custom_taxonomies[$t-&gt;parent]-&gt;name : ''; ?&gt;&lt;/wp:term_parent&gt;&lt;?php wxr_term_name( $t ); ?&gt;&lt;?php wxr_term_description( $t ); ?&gt;&lt;/wp:term&gt;
+        &lt;?php endforeach; endif; ?&gt;
+        
+        &lt;?php do_action( 'rss2_head' ); ?&gt;
</ins><span class="cx"> 
</span><del>-                        $is_sticky = 0;
-                        if ( is_sticky( $post-&gt;ID ) )
-                                $is_sticky = 1;
</del><ins>+        &lt;?php if ( $post_ids ) {
+        global $wp_query;
+        $wp_query-&gt;in_the_loop = true;  // Fake being in the loop.
+        
+        // fetch 20 posts at a time rather than loading the entire table into memory
+        while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
+        $where = &quot;WHERE ID IN (&quot; . join( ',', $next_posts ) . &quot;)&quot;;
+        $posts = $wpdb-&gt;get_results( &quot;SELECT * FROM $wpdb-&gt;posts $where ORDER BY post_date_gmt ASC&quot; );
+        
+        // Begin Loop
+        foreach ($posts as $post) {
+        setup_postdata( $post );
</ins><span class="cx"> 
</span><del>-?&gt;
-&lt;item&gt;
-&lt;title&gt;&lt;?php echo apply_filters('the_title_rss', $post-&gt;post_title); ?&gt;&lt;/title&gt;
-&lt;link&gt;&lt;?php the_permalink_rss() ?&gt;&lt;/link&gt;
-&lt;pubDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?&gt;&lt;/pubDate&gt;
-&lt;dc:creator&gt;&lt;?php echo wxr_cdata(get_the_author()); ?&gt;&lt;/dc:creator&gt;
-&lt;?php wxr_post_taxonomy() ?&gt;
</del><ins>+        $is_sticky = 0;
+        if ( is_sticky( $post-&gt;ID ) )
+                $is_sticky = 1;
</ins><span class="cx"> 
</span><del>-&lt;guid isPermaLink=&quot;false&quot;&gt;&lt;?php the_guid(); ?&gt;&lt;/guid&gt;
-&lt;description&gt;&lt;/description&gt;
-&lt;content:encoded&gt;&lt;?php echo wxr_cdata( apply_filters('the_content_export', $post-&gt;post_content) ); ?&gt;&lt;/content:encoded&gt;
-&lt;excerpt:encoded&gt;&lt;?php echo wxr_cdata( apply_filters('the_excerpt_export', $post-&gt;post_excerpt) ); ?&gt;&lt;/excerpt:encoded&gt;
-&lt;wp:post_id&gt;&lt;?php echo $post-&gt;ID; ?&gt;&lt;/wp:post_id&gt;
-&lt;wp:post_date&gt;&lt;?php echo $post-&gt;post_date; ?&gt;&lt;/wp:post_date&gt;
-&lt;wp:post_date_gmt&gt;&lt;?php echo $post-&gt;post_date_gmt; ?&gt;&lt;/wp:post_date_gmt&gt;
-&lt;wp:comment_status&gt;&lt;?php echo $post-&gt;comment_status; ?&gt;&lt;/wp:comment_status&gt;
-&lt;wp:ping_status&gt;&lt;?php echo $post-&gt;ping_status; ?&gt;&lt;/wp:ping_status&gt;
-&lt;wp:post_name&gt;&lt;?php echo $post-&gt;post_name; ?&gt;&lt;/wp:post_name&gt;
-&lt;wp:status&gt;&lt;?php echo $post-&gt;post_status; ?&gt;&lt;/wp:status&gt;
-&lt;wp:post_parent&gt;&lt;?php echo $post-&gt;post_parent; ?&gt;&lt;/wp:post_parent&gt;
-&lt;wp:menu_order&gt;&lt;?php echo $post-&gt;menu_order; ?&gt;&lt;/wp:menu_order&gt;
-&lt;wp:post_type&gt;&lt;?php echo $post-&gt;post_type; ?&gt;&lt;/wp:post_type&gt;
-&lt;wp:post_password&gt;&lt;?php echo $post-&gt;post_password; ?&gt;&lt;/wp:post_password&gt;
-&lt;wp:is_sticky&gt;&lt;?php echo $is_sticky; ?&gt;&lt;/wp:is_sticky&gt;
-&lt;?php
-if ($post-&gt;post_type == 'attachment') { ?&gt;
-&lt;wp:attachment_url&gt;&lt;?php echo wp_get_attachment_url($post-&gt;ID); ?&gt;&lt;/wp:attachment_url&gt;
-&lt;?php } ?&gt;
-&lt;?php
-$postmeta = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;postmeta WHERE post_id = %d&quot;, $post-&gt;ID) );
-if ( $postmeta ) {
-?&gt;
-&lt;?php foreach( $postmeta as $meta ) { ?&gt;
-&lt;wp:postmeta&gt;
-&lt;wp:meta_key&gt;&lt;?php echo $meta-&gt;meta_key; ?&gt;&lt;/wp:meta_key&gt;
-&lt;wp:meta_value&gt;&lt;?php echo wxr_cdata( $meta-&gt;meta_value ); ?&gt;&lt;/wp:meta_value&gt;
-&lt;/wp:postmeta&gt;
-&lt;?php } ?&gt;
-&lt;?php } ?&gt;
-&lt;?php
-$comments = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;comments WHERE comment_post_ID = %d&quot;, $post-&gt;ID) );
-if ( $comments ) { foreach ( $comments as $c ) { ?&gt;
-&lt;wp:comment&gt;
-&lt;wp:comment_id&gt;&lt;?php echo $c-&gt;comment_ID; ?&gt;&lt;/wp:comment_id&gt;
-&lt;wp:comment_author&gt;&lt;?php echo wxr_cdata($c-&gt;comment_author); ?&gt;&lt;/wp:comment_author&gt;
-&lt;wp:comment_author_email&gt;&lt;?php echo $c-&gt;comment_author_email; ?&gt;&lt;/wp:comment_author_email&gt;
-&lt;wp:comment_author_url&gt;&lt;?php echo esc_url_raw( $c-&gt;comment_author_url ); ?&gt;&lt;/wp:comment_author_url&gt;
-&lt;wp:comment_author_IP&gt;&lt;?php echo $c-&gt;comment_author_IP; ?&gt;&lt;/wp:comment_author_IP&gt;
-&lt;wp:comment_date&gt;&lt;?php echo $c-&gt;comment_date; ?&gt;&lt;/wp:comment_date&gt;
-&lt;wp:comment_date_gmt&gt;&lt;?php echo $c-&gt;comment_date_gmt; ?&gt;&lt;/wp:comment_date_gmt&gt;
-&lt;wp:comment_content&gt;&lt;?php echo wxr_cdata($c-&gt;comment_content) ?&gt;&lt;/wp:comment_content&gt;
-&lt;wp:comment_approved&gt;&lt;?php echo $c-&gt;comment_approved; ?&gt;&lt;/wp:comment_approved&gt;
-&lt;wp:comment_type&gt;&lt;?php echo $c-&gt;comment_type; ?&gt;&lt;/wp:comment_type&gt;
-&lt;wp:comment_parent&gt;&lt;?php echo $c-&gt;comment_parent; ?&gt;&lt;/wp:comment_parent&gt;
-&lt;wp:comment_user_id&gt;&lt;?php echo $c-&gt;user_id; ?&gt;&lt;/wp:comment_user_id&gt;
-&lt;/wp:comment&gt;
-&lt;?php } } ?&gt;
</del><ins>+        ?&gt;
+        &lt;item&gt;
+                &lt;title&gt;&lt;?php echo apply_filters( 'the_title_rss', $post-&gt;post_title ); ?&gt;&lt;/title&gt;
+                &lt;link&gt;&lt;?php the_permalink_rss() ?&gt;&lt;/link&gt;
+                &lt;pubDate&gt;&lt;?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?&gt;&lt;/pubDate&gt;
+                &lt;dc:creator&gt;&lt;?php echo wxr_cdata( get_the_author() ); ?&gt;&lt;/dc:creator&gt;
+                &lt;?php wxr_post_taxonomy() ?&gt;
+        
+                &lt;guid isPermaLink=&quot;false&quot;&gt;&lt;?php the_guid(); ?&gt;&lt;/guid&gt;
+                &lt;description&gt;&lt;/description&gt;
+                &lt;content:encoded&gt;&lt;?php echo wxr_cdata( apply_filters( 'the_content_export', $post-&gt;post_content ) ); ?&gt;&lt;/content:encoded&gt;
+                &lt;excerpt:encoded&gt;&lt;?php echo wxr_cdata( apply_filters( 'the_excerpt_export', $post-&gt;post_excerpt ) ); ?&gt;&lt;/excerpt:encoded&gt;
+                &lt;wp:post_id&gt;&lt;?php echo $post-&gt;ID; ?&gt;&lt;/wp:post_id&gt;
+                &lt;wp:post_date&gt;&lt;?php echo $post-&gt;post_date; ?&gt;&lt;/wp:post_date&gt;
+                &lt;wp:post_date_gmt&gt;&lt;?php echo $post-&gt;post_date_gmt; ?&gt;&lt;/wp:post_date_gmt&gt;
+                &lt;wp:comment_status&gt;&lt;?php echo $post-&gt;comment_status; ?&gt;&lt;/wp:comment_status&gt;
+                &lt;wp:ping_status&gt;&lt;?php echo $post-&gt;ping_status; ?&gt;&lt;/wp:ping_status&gt;
+                &lt;wp:post_name&gt;&lt;?php echo $post-&gt;post_name; ?&gt;&lt;/wp:post_name&gt;
+                &lt;wp:status&gt;&lt;?php echo $post-&gt;post_status; ?&gt;&lt;/wp:status&gt;
+                &lt;wp:post_parent&gt;&lt;?php echo $post-&gt;post_parent; ?&gt;&lt;/wp:post_parent&gt;
+                &lt;wp:menu_order&gt;&lt;?php echo $post-&gt;menu_order; ?&gt;&lt;/wp:menu_order&gt;
+                &lt;wp:post_type&gt;&lt;?php echo $post-&gt;post_type; ?&gt;&lt;/wp:post_type&gt;
+                &lt;wp:post_password&gt;&lt;?php echo $post-&gt;post_password; ?&gt;&lt;/wp:post_password&gt;
+                &lt;wp:is_sticky&gt;&lt;?php echo $is_sticky; ?&gt;&lt;/wp:is_sticky&gt;
+                &lt;?php
+                if ( $post-&gt;post_type == 'attachment' ) { ?&gt;
+                &lt;wp:attachment_url&gt;&lt;?php echo wp_get_attachment_url( $post-&gt;ID ); ?&gt;&lt;/wp:attachment_url&gt;
+                &lt;?php } ?&gt;
+                &lt;?php
+                $postmeta = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;postmeta WHERE post_id = %d&quot;, $post-&gt;ID ) );
+                if ( $postmeta ) {
+                ?&gt;
+                &lt;?php foreach( $postmeta as $meta ) { ?&gt;
+                &lt;wp:postmeta&gt;
+                &lt;wp:meta_key&gt;&lt;?php echo $meta-&gt;meta_key; ?&gt;&lt;/wp:meta_key&gt;
+                &lt;wp:meta_value&gt;&lt;?php echo wxr_cdata( $meta-&gt;meta_value ); ?&gt;&lt;/wp:meta_value&gt;
+                &lt;/wp:postmeta&gt;
+                &lt;?php } ?&gt;
+                &lt;?php } ?&gt;
+                &lt;?php
+                $comments = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;comments WHERE comment_post_ID = %d&quot;, $post-&gt;ID ) );
+                if ( $comments ) { foreach ( $comments as $c ) { ?&gt;
+                &lt;wp:comment&gt;
+                &lt;wp:comment_id&gt;&lt;?php echo $c-&gt;comment_ID; ?&gt;&lt;/wp:comment_id&gt;
+                &lt;wp:comment_author&gt;&lt;?php echo wxr_cdata( $c-&gt;comment_author ); ?&gt;&lt;/wp:comment_author&gt;
+                &lt;wp:comment_author_email&gt;&lt;?php echo $c-&gt;comment_author_email; ?&gt;&lt;/wp:comment_author_email&gt;
+                &lt;wp:comment_author_url&gt;&lt;?php echo esc_url_raw( $c-&gt;comment_author_url ); ?&gt;&lt;/wp:comment_author_url&gt;
+                &lt;wp:comment_author_IP&gt;&lt;?php echo $c-&gt;comment_author_IP; ?&gt;&lt;/wp:comment_author_IP&gt;
+                &lt;wp:comment_date&gt;&lt;?php echo $c-&gt;comment_date; ?&gt;&lt;/wp:comment_date&gt;
+                &lt;wp:comment_date_gmt&gt;&lt;?php echo $c-&gt;comment_date_gmt; ?&gt;&lt;/wp:comment_date_gmt&gt;
+                &lt;wp:comment_content&gt;&lt;?php echo wxr_cdata( $c-&gt;comment_content ) ?&gt;&lt;/wp:comment_content&gt;
+                &lt;wp:comment_approved&gt;&lt;?php echo $c-&gt;comment_approved; ?&gt;&lt;/wp:comment_approved&gt;
+                &lt;wp:comment_type&gt;&lt;?php echo $c-&gt;comment_type; ?&gt;&lt;/wp:comment_type&gt;
+                &lt;wp:comment_parent&gt;&lt;?php echo $c-&gt;comment_parent; ?&gt;&lt;/wp:comment_parent&gt;
+                &lt;wp:comment_user_id&gt;&lt;?php echo $c-&gt;user_id; ?&gt;&lt;/wp:comment_user_id&gt;
+                &lt;/wp:comment&gt;
+                &lt;?php } } ?&gt;
</ins><span class="cx">         &lt;/item&gt;
</span><del>-&lt;?php } } } ?&gt;
</del><ins>+        &lt;?php 
+        } 
+        }
+} ?&gt;
</ins><span class="cx"> &lt;/channel&gt;
</span><span class="cx"> &lt;/rss&gt;
</span><span class="cx"> &lt;?php
</span></span></pre>
</div>
</div>

</body>
</html>