export_wp

Generates the WXR export file for download.

Description

export_wp( (array) $args = array() ); 

Default behavior is to export all content, however, note that post content will only be exported for post types with the can_export argument enabled. Any posts with the 'auto-draft' status will be skipped.

Parameters (1)

0. $args — Optional. (array) => array()
Arguments for generating the WXR export file for download. Default empty array.

Options

  • content (string) => 'all'

    Type of content to export. If set, only the post content of this post type will be exported. Accepts all,, post , page, attachment, or a defined custom post. If an invalid custom post type is supplied, every post type for which can_export is enabled will be exported instead. If a valid custom post type is supplied but can_export is disabled, then posts will be exported instead. When all, is supplied, only post types with can_export enabled will be exported.

  • author (string) => false (all)

    Author to export content for. Only used when $content is post,, page., or attachment. Accepts false (all) or a specific author ID.

  • category (string) => is false (all categories)

    Category (slug) to export content for. Used only when $content is post.. If set, only post content assigned to '$category will be exported. Accepts false or a specific category slug.

  • start_date (string) => false (since the beginning of time)

    Start date to export content from. Expected date format is Y-m-d.. Used only when $content is post,, page or attachment.

  • end_date (string) => false (latest publish date)

    End date to export content to. Expected date format is Y-m-d.. Used only when $content is post,, page or attachment.

array(

    /**
     * Type of content to export. If set, only the post content of this post type will be exported.
     * Accepts 'all', 'post', 'page', 'attachment', or a defined custom post. If an invalid custom
     * post type is supplied, every post type for which `can_export` is enabled will be exported
     * instead. If a valid custom post type is supplied but `can_export` is disabled, then 'posts'
     * will be exported instead. When 'all' is supplied, only post types with `can_export` enabled
     * will be exported.
     *
     * @type string
     * @default 'all'
     */
    'content' => 'all',

    /**
     * Author to export content for. Only used when `$content` is 'post', 'page', or 'attachment'.
     * Accepts false (all) or a specific author ID.
     *
     * @type string
     * @default false (all)
     */
    'author' => false (all),

    /**
     * Category (slug) to export content for. Used only when `$content` is 'post'. If set, only post
     * content assigned to `$category will be exported. Accepts false or a specific category slug.
     *
     * @type string
     * @default is false (all categories)
     */
    'category' => is false (all categories),

    /**
     * Start date to export content from. Expected date format is 'Y-m-d'. Used only when `$content`
     * is 'post', 'page' or 'attachment'.
     *
     * @type string
     * @default false (since the beginning of time)
     */
    'start_date' => false (since the beginning of time),

    /**
     * End date to export content to. Expected date format is 'Y-m-d'. Used only when `$content` is
     * 'post', 'page' or 'attachment'.
     *
     * @type string
     * @default false (latest publish date)
     */
    'end_date' => false (latest publish date)
);        


Usage

  1. if ( !function_exists( 'export_wp' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/export.php'; 
  3.  
  4. // Optional. Arguments for generating the WXR export file for download. Default empty array. 
  5. $args = array( 
  6. 'content' => 'all', 
  7. 'author' => false (all), 
  8. 'category' => is false (all categories), 
  9. 'start_date' => false (since the beginning of time), 
  10. 'end_date' => false (latest publish date) 
  11. ); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = export_wp($args); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/export.php  
  1. function export_wp( $args = array() ) { 
  2. global $wpdb, $post; 
  3.  
  4. $defaults = array( 'content' => 'all', 'author' => false, 'category' => false,  
  5. 'start_date' => false, 'end_date' => false, 'status' => false,  
  6. ); 
  7. $args = wp_parse_args( $args, $defaults ); 
  8.  
  9. /** 
  10. * Fires at the beginning of an export, before any headers are sent. 
  11. * @since 2.3.0 
  12. * @param array $args An array of export arguments. 
  13. */ 
  14. do_action( 'export_wp', $args ); 
  15.  
  16. $sitename = sanitize_key( get_bloginfo( 'name' ) ); 
  17. if ( ! empty( $sitename ) ) { 
  18. $sitename .= '.'; 
  19. $date = date( 'Y-m-d' ); 
  20. $wp_filename = $sitename . 'wordpress.' . $date . '.xml'; 
  21. /** 
  22. * Filters the export filename. 
  23. * @since 4.4.0 
  24. * @param string $wp_filename The name of the file for download. 
  25. * @param string $sitename The site name. 
  26. * @param string $date Today's date, formatted. 
  27. */ 
  28. $filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date ); 
  29.  
  30. header( 'Content-Description: File Transfer' ); 
  31. header( 'Content-Disposition: attachment; filename=' . $filename ); 
  32. header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); 
  33.  
  34. if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { 
  35. $ptype = get_post_type_object( $args['content'] ); 
  36. if ( ! $ptype->can_export ) 
  37. $args['content'] = 'post'; 
  38.  
  39. $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); 
  40. } else { 
  41. $post_types = get_post_types( array( 'can_export' => true ) ); 
  42. $esses = array_fill( 0, count($post_types), '%s' ); 
  43. $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ', ', $esses ) . ')', $post_types ); 
  44.  
  45. if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) 
  46. $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); 
  47. else 
  48. $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; 
  49.  
  50. $join = ''; 
  51. if ( $args['category'] && 'post' == $args['content'] ) { 
  52. if ( $term = term_exists( $args['category'], 'category' ) ) { 
  53. $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; 
  54. $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); 
  55.  
  56. if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) { 
  57. if ( $args['author'] ) 
  58. $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); 
  59.  
  60. if ( $args['start_date'] ) 
  61. $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) ); 
  62.  
  63. if ( $args['end_date'] ) 
  64. $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); 
  65.  
  66. // Grab a snapshot of post IDs, just in case it changes during the export. 
  67. $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); 
  68.  
  69. /** 
  70. * Get the requested terms ready, empty unless posts filtered by category 
  71. * or all content. 
  72. */ 
  73. $cats = $tags = $terms = array(); 
  74. if ( isset( $term ) && $term ) { 
  75. $cat = get_term( $term['term_id'], 'category' ); 
  76. $cats = array( $cat->term_id => $cat ); 
  77. unset( $term, $cat ); 
  78. } elseif ( 'all' == $args['content'] ) { 
  79. $categories = (array) get_categories( array( 'get' => 'all' ) ); 
  80. $tags = (array) get_tags( array( 'get' => 'all' ) ); 
  81.  
  82. $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 
  83. $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 
  84.  
  85. // Put categories in order with no child going before its parent. 
  86. while ( $cat = array_shift( $categories ) ) { 
  87. if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 
  88. $cats[$cat->term_id] = $cat; 
  89. else 
  90. $categories[] = $cat; 
  91.  
  92. // Put terms in order with no child going before its parent. 
  93. while ( $t = array_shift( $custom_terms ) ) { 
  94. if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) 
  95. $terms[$t->term_id] = $t; 
  96. else 
  97. $custom_terms[] = $t; 
  98.  
  99. unset( $categories, $custom_taxonomies, $custom_terms ); 
  100.  
  101. /** 
  102. * Wrap given string in XML CDATA tag. 
  103. * @since 2.1.0 
  104. * @param string $str String to wrap in XML CDATA tag. 
  105. * @return string 
  106. */ 
  107. function wxr_cdata( $str ) { 
  108. if ( ! seems_utf8( $str ) ) { 
  109. $str = utf8_encode( $str ); 
  110. // $str = ent2ncr(esc_html($str)); 
  111. $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>'; 
  112.  
  113. return $str; 
  114.  
  115. /** 
  116. * Return the URL of the site 
  117. * @since 2.5.0 
  118. * @return string Site URL. 
  119. */ 
  120. function wxr_site_url() { 
  121. // Multisite: the base URL. 
  122. if ( is_multisite() ) 
  123. return network_home_url(); 
  124. // WordPress (single site): the blog URL. 
  125. else 
  126. return get_bloginfo_rss( 'url' ); 
  127.  
  128. /** 
  129. * Output a cat_name XML tag from a given category object 
  130. * @since 2.1.0 
  131. * @param object $category Category Object 
  132. */ 
  133. function wxr_cat_name( $category ) { 
  134. if ( empty( $category->name ) ) 
  135. return; 
  136.  
  137. echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n"; 
  138.  
  139. /** 
  140. * Output a category_description XML tag from a given category object 
  141. * @since 2.1.0 
  142. * @param object $category Category Object 
  143. */ 
  144. function wxr_category_description( $category ) { 
  145. if ( empty( $category->description ) ) 
  146. return; 
  147.  
  148. echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n"; 
  149.  
  150. /** 
  151. * Output a tag_name XML tag from a given tag object 
  152. * @since 2.3.0 
  153. * @param object $tag Tag Object 
  154. */ 
  155. function wxr_tag_name( $tag ) { 
  156. if ( empty( $tag->name ) ) 
  157. return; 
  158.  
  159. echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n"; 
  160.  
  161. /** 
  162. * Output a tag_description XML tag from a given tag object 
  163. * @since 2.3.0 
  164. * @param object $tag Tag Object 
  165. */ 
  166. function wxr_tag_description( $tag ) { 
  167. if ( empty( $tag->description ) ) 
  168. return; 
  169.  
  170. echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n"; 
  171.  
  172. /** 
  173. * Output a term_name XML tag from a given term object 
  174. * @since 2.9.0 
  175. * @param object $term Term Object 
  176. */ 
  177. function wxr_term_name( $term ) { 
  178. if ( empty( $term->name ) ) 
  179. return; 
  180.  
  181. echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n"; 
  182.  
  183. /** 
  184. * Output a term_description XML tag from a given term object 
  185. * @since 2.9.0 
  186. * @param object $term Term Object 
  187. */ 
  188. function wxr_term_description( $term ) { 
  189. if ( empty( $term->description ) ) 
  190. return; 
  191.  
  192. echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n"; 
  193.  
  194. /** 
  195. * Output term meta XML tags for a given term object. 
  196. * @since 4.6.0 
  197. * @param WP_Term $term Term object. 
  198. */ 
  199. function wxr_term_meta( $term ) { 
  200. global $wpdb; 
  201.  
  202. $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) ); 
  203.  
  204. foreach ( $termmeta as $meta ) { 
  205. /** 
  206. * Filters whether to selectively skip term meta used for WXR exports. 
  207. * Returning a truthy value to the filter will skip the current meta 
  208. * object from being exported. 
  209. * @since 4.6.0 
  210. * @param bool $skip Whether to skip the current piece of term meta. Default false. 
  211. * @param string $meta_key Current meta key. 
  212. * @param object $meta Current meta object. 
  213. */ 
  214. if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) { 
  215. printf( "\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>%s</wp:meta_key>\n\t\t\t<wp:meta_value>%s</wp:meta_value>\n\t\t</wp:termmeta>\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) ); 
  216.  
  217. /** 
  218. * Output list of authors with posts 
  219. * @since 3.1.0 
  220. * @global wpdb $wpdb WordPress database abstraction object. 
  221. * @param array $post_ids Array of post IDs to filter the query by. Optional. 
  222. */ 
  223. function wxr_authors_list( array $post_ids = null ) { 
  224. global $wpdb; 
  225.  
  226. if ( !empty( $post_ids ) ) { 
  227. $post_ids = array_map( 'absint', $post_ids ); 
  228. $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')'; 
  229. } else { 
  230. $and = ''; 
  231.  
  232. $authors = array(); 
  233. $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" ); 
  234. foreach ( (array) $results as $result ) 
  235. $authors[] = get_userdata( $result->post_author ); 
  236.  
  237. $authors = array_filter( $authors ); 
  238.  
  239. foreach ( $authors as $author ) { 
  240. echo "\t<wp:author>"; 
  241. echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>'; 
  242. echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>'; 
  243. echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>'; 
  244. echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>'; 
  245. echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>'; 
  246. echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>'; 
  247. echo "</wp:author>\n"; 
  248.  
  249. /** 
  250. * Output all navigation menu terms 
  251. * @since 3.1.0 
  252. */ 
  253. function wxr_nav_menu_terms() { 
  254. $nav_menus = wp_get_nav_menus(); 
  255. if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) 
  256. return; 
  257.  
  258. foreach ( $nav_menus as $menu ) { 
  259. echo "\t<wp:term>"; 
  260. echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>'; 
  261. echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>'; 
  262. echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>'; 
  263. wxr_term_name( $menu ); 
  264. echo "</wp:term>\n"; 
  265.  
  266. /** 
  267. * Output list of taxonomy terms, in XML tag format, associated with a post 
  268. * @since 2.3.0 
  269. */ 
  270. function wxr_post_taxonomy() { 
  271. $post = get_post(); 
  272.  
  273. $taxonomies = get_object_taxonomies( $post->post_type ); 
  274. if ( empty( $taxonomies ) ) 
  275. return; 
  276. $terms = wp_get_object_terms( $post->ID, $taxonomies ); 
  277.  
  278. foreach ( (array) $terms as $term ) { 
  279. echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n"; 
  280.  
  281. /** 
  282. * @param bool $return_me 
  283. * @param string $meta_key 
  284. * @return bool 
  285. */ 
  286. function wxr_filter_postmeta( $return_me, $meta_key ) { 
  287. if ( '_edit_lock' == $meta_key ) 
  288. $return_me = true; 
  289. return $return_me; 
  290. add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 ); 
  291.  
  292. echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n"; 
  293.  
  294. ?> 
  295. <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. --> 
  296. <!-- It contains information about your site's posts, pages, comments, categories, and other content. --> 
  297. <!-- You may use this file to transfer that content from one site to another. --> 
  298. <!-- This file is not intended to serve as a complete backup of your site. --> 
  299.  
  300. <!-- To import this information into a WordPress site follow these steps: --> 
  301. <!-- 1. Log in to that site as an administrator. --> 
  302. <!-- 2. Go to Tools: Import in the WordPress admin panel. --> 
  303. <!-- 3. Install the "WordPress" importer from the list. --> 
  304. <!-- 4. Activate & Run Importer. --> 
  305. <!-- 5. Upload this file using the form provided on that page. --> 
  306. <!-- 6. You will first be asked to map the authors in this export file to users --> 
  307. <!-- on the site. For each author, you may choose to map to an --> 
  308. <!-- existing user on the site or to create a new user. --> 
  309. <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. --> 
  310. <!-- contained in this file into your site. --> 
  311.  
  312. <?php the_generator( 'export' ); ?> 
  313. <rss version="2.0" 
  314. xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/" 
  315. xmlns:content="http://purl.org/rss/1.0/modules/content/" 
  316. xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
  317. xmlns:dc="http://purl.org/dc/elements/1.1/" 
  318. xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/" 
  319.  
  320. <channel> 
  321. <title><?php bloginfo_rss( 'name' ); ?></title> 
  322. <link><?php bloginfo_rss( 'url' ); ?></link> 
  323. <description><?php bloginfo_rss( 'description' ); ?></description> 
  324. <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate> 
  325. <language><?php bloginfo_rss( 'language' ); ?></language> 
  326. <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version> 
  327. <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url> 
  328. <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url> 
  329.  
  330. <?php wxr_authors_list( $post_ids ); ?> 
  331.  
  332. <?php foreach ( $cats as $c ) : ?> 
  333. <wp:category> 
  334. <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id> 
  335. <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename> 
  336. <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent> 
  337. <?php wxr_cat_name( $c ); 
  338. wxr_category_description( $c ); 
  339. wxr_term_meta( $c ); ?> 
  340. </wp:category> 
  341. <?php endforeach; ?> 
  342. <?php foreach ( $tags as $t ) : ?> 
  343. <wp:tag> 
  344. <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id> 
  345. <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug> 
  346. <?php wxr_tag_name( $t ); 
  347. wxr_tag_description( $t ); 
  348. wxr_term_meta( $t ); ?> 
  349. </wp:tag> 
  350. <?php endforeach; ?> 
  351. <?php foreach ( $terms as $t ) : ?> 
  352. <wp:term> 
  353. <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id> 
  354. <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy> 
  355. <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug> 
  356. <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent> 
  357. <?php wxr_term_name( $t ); 
  358. wxr_term_description( $t ); 
  359. wxr_term_meta( $t ); ?> 
  360. </wp:term> 
  361. <?php endforeach; ?> 
  362. <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?> 
  363.  
  364. <?php 
  365. /** This action is documented in wp-includes/feed-rss2.php */ 
  366. ?> 
  367.  
  368. <?php if ( $post_ids ) { 
  369. /** 
  370. * @global WP_Query $wp_query 
  371. */ 
  372. global $wp_query; 
  373.  
  374. // Fake being in the loop. 
  375. $wp_query->in_the_loop = true; 
  376.  
  377. // Fetch 20 posts at a time rather than loading the entire table into memory. 
  378. while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { 
  379. $where = 'WHERE ID IN (' . join( ', ', $next_posts ) . ')'; 
  380. $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); 
  381.  
  382. // Begin Loop. 
  383. foreach ( $posts as $post ) { 
  384. setup_postdata( $post ); 
  385. $is_sticky = is_sticky( $post->ID ) ? 1 : 0; 
  386. ?> 
  387. <item> 
  388. <title><?php 
  389. /** This filter is documented in wp-includes/feed.php */ 
  390. echo apply_filters( 'the_title_rss', $post->post_title ); 
  391. ?></title> 
  392. <link><?php the_permalink_rss() ?></link> 
  393. <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate> 
  394. <dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator> 
  395. <guid isPermaLink="false"><?php the_guid(); ?></guid> 
  396. <description></description> 
  397. <content:encoded><?php 
  398. /** 
  399. * Filters the post content used for WXR exports. 
  400. * @since 2.5.0 
  401. * @param string $post_content Content of the current post. 
  402. */ 
  403. echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); 
  404. ?></content:encoded> 
  405. <excerpt:encoded><?php 
  406. /** 
  407. * Filters the post excerpt used for WXR exports. 
  408. * @since 2.6.0 
  409. * @param string $post_excerpt Excerpt for the current post. 
  410. */ 
  411. echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); 
  412. ?></excerpt:encoded> 
  413. <wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id> 
  414. <wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date> 
  415. <wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt> 
  416. <wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status> 
  417. <wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status> 
  418. <wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name> 
  419. <wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status> 
  420. <wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent> 
  421. <wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order> 
  422. <wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type> 
  423. <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password> 
  424. <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky> 
  425. <?php if ( $post->post_type == 'attachment' ) : ?> 
  426. <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url> 
  427. <?php endif; ?> 
  428. <?php wxr_post_taxonomy(); ?> 
  429. <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); 
  430. foreach ( $postmeta as $meta ) : 
  431. /** 
  432. * Filters whether to selectively skip post meta used for WXR exports. 
  433. * Returning a truthy value to the filter will skip the current meta 
  434. * object from being exported. 
  435. * @since 3.3.0 
  436. * @param bool $skip Whether to skip the current post meta. Default false. 
  437. * @param string $meta_key Current meta key. 
  438. * @param object $meta Current meta object. 
  439. */ 
  440. if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) 
  441. continue; 
  442. ?> 
  443. <wp:postmeta> 
  444. <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> 
  445. <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> 
  446. </wp:postmeta> 
  447. <?php endforeach; 
  448.  
  449. $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); 
  450. $comments = array_map( 'get_comment', $_comments ); 
  451. foreach ( $comments as $c ) : ?> 
  452. <wp:comment> 
  453. <wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id> 
  454. <wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author> 
  455. <wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email> 
  456. <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url> 
  457. <wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP> 
  458. <wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date> 
  459. <wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt> 
  460. <wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content> 
  461. <wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved> 
  462. <wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type> 
  463. <wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent> 
  464. <wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id> 
  465. <?php $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); 
  466. foreach ( $c_meta as $meta ) : 
  467. /** 
  468. * Filters whether to selectively skip comment meta used for WXR exports. 
  469. * Returning a truthy value to the filter will skip the current meta 
  470. * object from being exported. 
  471. * @since 4.0.0 
  472. * @param bool $skip Whether to skip the current comment meta. Default false. 
  473. * @param string $meta_key Current meta key. 
  474. * @param object $meta Current meta object. 
  475. */ 
  476. if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) { 
  477. continue; 
  478. ?> 
  479. <wp:commentmeta> 
  480. <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> 
  481. <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> 
  482. </wp:commentmeta> 
  483. <?php endforeach; ?> 
  484. </wp:comment> 
  485. <?php endforeach; ?> 
  486. </item> 
  487. <?php 
  488. } ?> 
  489. </channel> 
  490. </rss> 
  491. <?php