WordPress.org

Make WordPress Core

Ticket #5137: intersection.diff

File intersection.diff, 1.4 KB (added by ryan, 7 years ago)

New query for tag_slugand from Alexander Concha

  • wp-includes/query.php

     
    10641064                } 
    10651065 
    10661066                if ( !empty($q['tag_slug__and']) ) { 
    1067                         $count = 0; 
    1068                         foreach ( $q['tag_slug__and'] as $tag_and ) { 
    1069                                 $join .= " LEFT JOIN $wpdb->term_relationships AS tr$count ON ($wpdb->posts.ID = tr$count.object_id) LEFT JOIN $wpdb->term_taxonomy AS tt$count ON (tr$count.term_taxonomy_id = tt$count.term_taxonomy_id) LEFT JOIN $wpdb->terms AS term$count ON (tt$count.term_id = term$count.term_id) "; 
    1070                                 $whichcat .= " AND term$count.slug = '$tag_and' "; 
    1071                                 $count++; 
    1072                         } 
     1067                        $tsql = "SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) LEFT JOIN $wpdb->terms t ON (tt.term_id = t.term_id)"; 
     1068                        $tsql .= "WHERE tt.taxonomy = 'post_tag' AND t.slug IN ('" . implode("', '", $q['tag_slug__and']) . "')"; 
     1069                        $tsql .= "GROUP BY p.ID HAVING count(p.ID) = " . count($q['tag_slug__and']); 
     1070                        $post_ids = $wpdb->get_col($tsql); 
     1071                         
     1072                        if ( count($post_ids) ) 
     1073                                $where .= "AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; 
     1074                        else 
     1075                                $where = "AND 0 = 1"; 
     1076 
    10731077                        $reqtag = is_term( $q['tag_slug__and'][0], 'post_tag' ); 
    10741078                        if ( !empty($reqtag) ) 
    10751079                                $q['tag_id'] = $reqtag['term_id'];