Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#15941 closed defect (bug) (fixed)

Wordpress 3.0 Multisite Export tag/category filter

Reported by: nootron's profile nootron Owned by: duck_'s profile 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:

  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);
		}
	}

Attachments (1)

15941.tt-id.diff (697 bytes) - added by duck_ 14 years ago.

Download all attachments as: .zip

Change History (5)

#1 @nacin
14 years ago

  • Owner set to duck_
  • Status changed from new to reviewing

@duck_
14 years ago

#2 @duck_
14 years ago

  • Keywords has-patch added; export category term removed
  • Milestone changed from Awaiting Review to 3.1

Specifically knew about this faulty logic and still managed to make the same mistake, argh!

Related: #14058, #15197

#3 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [17108]) Use term_taxonomy_id instead of term_id. Props duck_, nootron. fixes #15941

This ticket was mentioned in Slack in #core by sergey. View the logs.


8 years ago

Note: See TracTickets for help on using tickets.