﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
15941,Wordpress 3.0 Multisite Export tag/category filter,nootron,duck_,"Exporting wordpress posts by term (category or tag) appears to return zero items, even if there are existing posts in that category.

To replicate:

1.  Create a post.  
2.  Assign it to a category
3.  Select Settings > Export
4.  Choose the category from the dropdown filter
5.  Export

I have tracked the cause down to a logic bug in /wp-admin/includes/export.php, code block beginning on line #64

{{{
	if ( $taxonomy && is_array( $taxonomy ) ) {
		foreach ( $taxonomy as $term_id ) {
			if ( $term_id != 'all' )
				$where .= $wpdb->prepare( ""AND ID IN (SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d) "", $term_id );
		}
	}
}}}

This join is not properly joining the term_RELATIONSHIP_id but instead attempts to join on the primary key.

This code appears to correct the bug and properly returns posts (and child attachments) that match the term:

{{{
	if ( $taxonomy && is_array( $taxonomy ) ) {
		foreach ( $taxonomy as $term_id ) {
			if ( $term_id != 'all' )
				$where .= $wpdb->prepare( ""AND ID IN (SELECT object_id FROM $wpdb->term_relationships 
                JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
                WHERE $wpdb->term_taxonomy.term_id = %d) "", $term_id ); 				
				
				/* Gets attachments */
				$where .= $wpdb->prepare( ""OR ( post_type = 'attachment' AND post_parent IN ( SELECT object_id FROM wbur_term_relationships
				JOIN wbur_term_taxonomy ON wbur_term_relationships.term_taxonomy_id = wbur_term_taxonomy.term_taxonomy_id
				WHERE wbur_term_taxonomy.term_id = %d )) "", $term_id);
		}
	}
}}}


",defect (bug),closed,normal,3.1,Administration,,major,fixed,has-patch,
