#15941 closed defect (bug) (fixed)
Wordpress 3.0 Multisite Export tag/category filter
Reported by: | nootron | Owned by: | duck_ |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | major | Version: | |
Component: | Administration | Keywords: | has-patch |
Focuses: | Cc: |
Description
Exporting wordpress posts by term (category or tag) appears to return zero items, even if there are existing posts in that category.
To replicate:
- Create a post.
- Assign it to a category
- Select Settings > Export
- Choose the category from the dropdown filter
- 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); } }
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Specifically knew about this faulty logic and still managed to make the same mistake, argh!
Related: #14058, #15197