Advanced Export for WP & WPMU
[resolved] eliminating superfluous cat and tag records from posts o (6 posts)

  1. rcain
    Posted 4 years ago #

    whilst exporting posts ONLY, without cats, or tags - i noted that the exported post records still contained the tag/category references. this was not appropriate for my purposes where i wished to import plain vanilla posts into a new site with a brand new taxonomy structure - which i did not which to confuse/overwrite. (i intend to use auto-tagging of content then tags-to-cats converter to impose my new structure)

    the following mod simply ensure that post exports omit the unnecessary category and tag information IFF you have also selected NOT to export either tags or categories from the admin menu.

    changes required for this are:

    file: ra-export.php
    line: right at end of file
    add new function:

    /*mod jrc 290312 - new func to omit tags and cats for posts when unselected by terms option*/
    		function scl_wxr_post_taxonomy($terms = 'all') {
    			if (empty($terms) || $terms =='none') return;
    			$categories = get_the_category();
    			$tags = get_the_tags();
    			$the_list = '';
    			$filter = 'rss';
    			if ( ($terms == 'cats' || $terms =='all' ) && !empty($categories) ) foreach ( (array) $categories as $category ) {
    				$cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
    				// for backwards compatibility
    				$the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
    				// forwards compatibility: use a unique identifier for each cat to avoid clashes
    				// http://trac.wordpress.org/ticket/5447
    				$the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
    			if ( ($terms == 'tags' || $terms =='all' ) && !empty($tags) ) foreach ( (array) $tags as $tag ) {
    				$tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
    				$the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
    				// forwards compatibility as above
    				$the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
    			echo $the_list;
    /*end mod jrc 290312*/

    - this is very similar to the existing function wxr_post_taxonomy, except that it returns nothing unless specifcally requesting export of tag's, categories, or all.

    to go with this change ,
    same file,
    function: ra_export_wp
    line: around line 189

    change from:

    <?php wxr_post_taxonomy(); ?>

    change to:

    <?php scl_wxr_post_taxonomy($terms); ?>

    - thus calling the new function above.

    saves having a load of noisy tag and category data in the export file/imported database, if you didn't actually want them to go across anyway.

    this is only useful when exporting from older versions of WP using this plugin.

    however, this basic functionality may still be useful to consider as a core change to new WP native export for future release (or perhaps a filter). (maybe also http://wordpress.org/support/topic/plugin-advanced-export-for-wp-wpmu-how-to-export-attachments-only ).


  2. rcain - FYI, please remember to use pastebin.com if your code chunks are 'large' (which we deam as over ten lines). It makes our spam checker go a little bibbeldy :)

  3. Also see this post:

    The plugin is up for adoption.

  4. rcain
    Posted 4 years ago #

    Ipstenu - sure. sorry about that - ordinarily i would have used pastebin, but thought i'd get away with 20 lines odd. good to know the reason though.

    Antrea - good suggestion - i'll give it some thought - pretty up to my eyes in work at present (on data import in fact), but will certainly give it a look over when i'm finished.

    all the best.

  5. rcain
    Posted 4 years ago #

    PS. you can find my complete modified code here: http://pastebin.com/RVBQ7icG

    you may also be interested in this post concerning import of attachments (using plugin http://wordpress.org/extend/plugins/wordpress-importer/ ) here: http://wordpress.org/support/topic/plugin-wordpress-importer-not-importing-any-images-at-all (esp my notes concerning export/import of multiple batches).

    and my modified code for that plugin - here: http://pastebin.com/RVBQ7icG

  6. rcain
    Posted 4 years ago #

    oops!: that last link should have been - http://pastebin.com/Xx7Sj7vN

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Export for WP & WPMU
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic