WordPress.org

Support

Support » Plugins and Hacks » Advanced Export for WP & WPMU » [Resolved] [Plugin: Advanced Export for WP & WPMU] eliminating superfluous cat and tag records from posts o

[Resolved] [Plugin: Advanced Export for WP & WPMU] eliminating superfluous cat and tag records from posts o

  • 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 ).

    http://wordpress.org/extend/plugins/advanced-export-for-wp-wpmu/

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] [Plugin: Advanced Export for WP & WPMU] eliminating superfluous cat and tag records from posts o’ is closed to new replies.
Skip to toolbar