| 1054 | | if ( !empty($q['tag__and']) ) { |
| 1055 | | $count = 0; |
| 1056 | | foreach ( $q['tag__and'] as $tag_and ) { |
| 1057 | | $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) "; |
| 1058 | | $whichcat .= " AND tt$count.term_id = '$tag_and' "; |
| 1059 | | $count++; |
| | 1045 | $intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag'); |
| | 1046 | foreach ($intersections as $item => $taxonomy) { |
| | 1047 | if ( empty($q[$item]) ) continue; |
| | 1048 | |
| | 1049 | if ( $item != 'category__and' ) { |
| | 1050 | $reqtag = is_term( $q[$item][0], 'post_tag' ); |
| | 1051 | if ( !empty($reqtag) ) |
| | 1052 | $q['tag_id'] = $reqtag['term_id']; |
| 1066 | | 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++; |
| | 1055 | $taxonomy_field = $item == 'tag_slug__and' ? 'slug' : 'term_id'; |
| | 1056 | |
| | 1057 | $q[$item] = array_unique($q[$item]); |
| | 1058 | $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)"; |
| | 1059 | $tsql .= "WHERE tt.taxonomy = '$taxonomy' AND t.$taxonomy_field IN ('" . implode("', '", $q[$item]) . "')"; |
| | 1060 | $tsql .= "GROUP BY p.ID HAVING count(p.ID) = " . count($q[$item]); |
| | 1061 | |
| | 1062 | $post_ids = $wpdb->get_col($tsql); |
| | 1063 | |
| | 1064 | if ( count($post_ids) ) |
| | 1065 | $where .= "AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; |
| | 1066 | else { |
| | 1067 | $where = "AND 0 = 1"; |
| | 1068 | break; |