WordPress WXR Specification

前端 未结 2 2022
无人及你
无人及你 2021-02-07 00:55

I\'m trying to find a spec for the WordPress WXR import/export standard and I\'m unable to find any official documentation from WordPress on the standard.

Does anyone kn

相关标签:
2条回答
  • 2021-02-07 01:15

    I posed this question to John O'Nolan, a WordPress core developer, who forwarded my question to core committer Aaron Jorbin. O'Nolan responded by saying (I'm paraphrasing) that there isn't any official documentation on the WXR standard, but that reverse engineering a WXR export should give me all the information I need.

    O'Nolan also noted that data more complex than blog post content is likely best dealt with through a database conversion/migration, rather than an import. I tend to agree here.

    I found these two links to be of some help in my effort to reverse engineer the WXR standard:

    http://ipggi.wordpress.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/

    http://olalindberg.com/2008/write-your-own-wxr-file-to-migrate-custom-cms-to-wordpress/

    The latter link specifically deal with attachments, something crucial for my current project.

    I hope this helps anyone else who is curious about WXR.

    0 讨论(0)
  • 2021-02-07 01:21

    For those without a WordPress export who nonetheless need to make a WXR file, the code for the exporter is on the WordPress plugins' Trac server. Excerpt below, from the <rss> node to a couple object foreach loops:

    <?php the_generator( 'export' ); ?>
    <rss version="2.0"
        xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
    >
    
    <channel>
        <title><?php bloginfo_rss( 'name' ); ?></title>
        <link><?php bloginfo_rss( 'url' ); ?></link>
        <description><?php bloginfo_rss( 'description' ); ?></description>
        <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
        <language><?php bloginfo_rss( 'language' ); ?></language>
        <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
        <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
        <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
    
    <?php wxr_authors_list( $post_ids ); ?>
    
    <?php foreach ( $cats as $c ) : ?>
        <wp:category>
            <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
            <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
            <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent>
            <?php wxr_cat_name( $c );
            wxr_category_description( $c );
            wxr_term_meta( $c ); ?>
        </wp:category>
    <?php endforeach; ?>
    <?php foreach ( $tags as $t ) : ?>
        <wp:tag>
            <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
            <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
            <?php wxr_tag_name( $t );
            wxr_tag_description( $t );
            wxr_term_meta( $t ); ?>
        </wp:tag>
    <?php endforeach; ?>
    <?php foreach ( $terms as $t ) : ?>
        <wp:term>
            <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
            <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
            <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
            <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent>
            <?php wxr_term_name( $t );
            wxr_term_description( $t );
            wxr_term_meta( $t ); ?>
        </wp:term>
    <?php endforeach; ?>
    
    0 讨论(0)
提交回复
热议问题