Ticket #5433: 5433v2.diff
| File 5433v2.diff, 3.4 KB (added by turboguy, 4 years ago) |
|---|
-
query.php
1094 1094 $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); 1095 1095 $q['tag_slug__in'][] = $tag; 1096 1096 } 1097 } else if ( preg_match('/[+\s]+/', $q['tag']) ) {1097 } else if ( preg_match('/[+\s]+/', $q['tag']) || !empty($q['cat']) ) { 1098 1098 $tags = preg_split('/[+\s]+/', $q['tag']); 1099 1099 foreach ( (array) $tags as $tag ) { 1100 1100 $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); … … 1111 1111 $groupby = "{$wpdb->posts}.ID"; 1112 1112 } 1113 1113 1114 if ( !empty($q['tag__in']) ) {1114 if ( !empty($q['tag__in']) && empty($q['cat']) ) { 1115 1115 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) "; 1116 1116 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' "; 1117 1117 $include_tags = "'" . implode("', '", $q['tag__in']) . "'"; … … 1121 1121 $q['tag_id'] = $reqtag['term_id']; 1122 1122 } 1123 1123 1124 if ( !empty($q['tag_slug__in']) ) {1124 if ( !empty($q['tag_slug__in']) && empty($q['cat']) ) { 1125 1125 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) INNER JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) "; 1126 1126 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' "; 1127 1127 $include_tags = "'" . implode("', '", $q['tag_slug__in']) . "'"; … … 1140 1140 } 1141 1141 1142 1142 // Tag and slug intersections. 1143 $intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag'); 1143 $intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag', 'tag__in' => 'post_tag', 'tag_slug__in' => 'post_tag'); 1144 $tagin = array('tag__in', 'tag_slug__in'); // These are used to make some exceptions below 1144 1145 foreach ($intersections as $item => $taxonomy) { 1145 1146 if ( empty($q[$item]) ) continue; 1146 1147 if ( in_array($item, $tagin) && empty($q['cat']) ) continue; // We should already have what we need if categories aren't being used 1148 1147 1149 if ( $item != 'category__and' ) { 1148 1150 $reqtag = is_term( $q[$item][0], 'post_tag' ); 1149 1151 if ( !empty($reqtag) ) 1150 1152 $q['tag_id'] = $reqtag['term_id']; 1151 1153 } 1152 1154 1153 $taxonomy_field = $item == 'tag_slug__and'? 'slug' : 'term_id';1155 $taxonomy_field = $item == ('tag_slug__and' || 'tag_slug__in') ? 'slug' : 'term_id'; 1154 1156 1155 1157 $q[$item] = array_unique($q[$item]); 1156 1158 $tsql = "SELECT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)"; 1157 1159 $tsql .= " WHERE tt.taxonomy = '$taxonomy' AND t.$taxonomy_field IN ('" . implode("', '", $q[$item]) . "')"; 1158 $tsql .= " GROUP BY p.ID HAVING count(p.ID) = " . count($q[$item]); 1159 1160 if ( !in_array($item, $tagin) ) { // This next line is only helpful if we are doing an and relationship 1161 $tsql .= " GROUP BY p.ID HAVING count(p.ID) = " . count($q[$item]); 1162 } 1160 1163 $post_ids = $wpdb->get_col($tsql); 1161 1164 1162 1165 if ( count($post_ids) )
