diff --git a/features/export.feature b/features/export.feature index aa3818f2..8415ddea 100644 --- a/features/export.feature +++ b/features/export.feature @@ -1291,3 +1291,27 @@ Feature: Export content. """ 2 """ + + Scenario: Export term meta + Given a WP install + + When I run `wp term meta add 1 term_metakey term_metavalue` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp export` + And save STDOUT 'Writing to file %s' as {EXPORT_FILE} + Then the {EXPORT_FILE} file should contain: + """ + + """ + And the {EXPORT_FILE} file should contain: + """ + term_metakey + """ + And the {EXPORT_FILE} file should contain: + """ + + """ diff --git a/src/WP_Export_WXR_Formatter.php b/src/WP_Export_WXR_Formatter.php index fe6a29fb..e22c34e3 100644 --- a/src/WP_Export_WXR_Formatter.php +++ b/src/WP_Export_WXR_Formatter.php @@ -135,6 +135,7 @@ public function categories() { ->tag( 'wp:category_parent', $category->parent_slug ) ->optional_cdata( 'wp:cat_name', $category->name ) ->optional_cdata( 'wp:category_description', $category->description ) + ->oxymel( $this->term_meta( $category ) ) ->end; } return $oxymel->to_string(); @@ -259,6 +260,7 @@ protected function terms( $terms ) { $oxymel ->optional_cdata( 'wp:term_name', $term->name ) ->optional_cdata( 'wp:term_description', $term->description ) + ->oxymel( $this->term_meta( $term ) ) ->end; } return $oxymel->to_string(); @@ -279,4 +281,20 @@ protected function comment_meta( $comment ) { } return $oxymel; } + + protected function term_meta( $term ) { + global $wpdb; + $metas = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) ); + if ( ! $metas ) { + return new Oxymel(); + } + $oxymel = new WP_Export_Oxymel(); + foreach ( $metas as $meta ) { + $oxymel->tag( 'wp:termmeta' )->contains + ->tag( 'wp:meta_key', $meta->meta_key ) + ->tag( 'wp:meta_value' )->contains->cdata( $meta->meta_value )->end + ->end; + } + return $oxymel; + } }