Ticket #4895: tag_intersect_union.diff

File tag_intersect_union.diff, 5.3 kB (added by ryan, 1 year ago)
  • wp-includes/query.php

    old new  
    420420                } 
    421421 
    422422                $array_keys = array('category__in', 'category__not_in', 'category__and', 
    423                         'tag__in', 'tag__not_in', 'tag__and'); 
     423                        'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and'); 
    424424                 
    425425                foreach ( $array_keys as $key ) { 
    426426                        if ( !isset($array[$key])) 
     
    608608                                $this->is_category = true;       
    609609                        } 
    610610 
     611                        if ( !is_array($qv['tag_slug__in']) || empty($qv['tag_slug__in']) ) { 
     612                                $qv['tag_slug__in'] = array(); 
     613                        } else { 
     614                                $qv['tag_slug__in'] = array_map('sanitize_title', $qv['tag_slug__in']); 
     615                                $this->is_tag = true;    
     616                        } 
     617 
     618                        if ( !is_array($qv['tag_slug__and']) || empty($qv['tag_slug__amd']) ) { 
     619                                $qv['tag_slug__and'] = array(); 
     620                        } else { 
     621                                $qv['tag_slug__and'] = array_map('sanitize_title', $qv['tag_slug__and']); 
     622                                $this->is_tag = true;    
     623                        } 
     624 
    611625                        if ( empty($qv['author']) || ($qv['author'] == '0') ) { 
    612626                                $this->is_author = false; 
    613627                        } else { 
     
    984998 
    985999                // Tags 
    9861000                if ( '' != $q['tag'] ) { 
    987                         $reqtag = is_term( $q['tag'], 'post_tag' ); 
    988                         if ( !empty($reqtag) ) 
    989                                 $reqtag = $reqtag['term_id']; 
    990                         else 
    991                                 $reqtag = 0; 
     1001                        if ( strpos($q['tag'], ',') !== false ) { 
     1002                                $tags = preg_split('/[,\s]+/', $q['tag']); 
     1003                                foreach ( (array) $tags as $tag ) { 
     1004                                        $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); 
     1005                                        $q['tag_slug__in'][] = $tag; 
     1006                                } 
     1007                        } else if ( preg_match('/[+\s]+/', $q['tag']) ) { 
     1008                                $tags = preg_split('/[+\s]+/', $q['tag']); 
     1009                                foreach ( (array) $tags as $tag ) { 
     1010                                        $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); 
     1011                                        $q['tag_slug__and'][] = $tag; 
     1012                                } 
     1013                        } else { 
     1014                                $q['tag'] = sanitize_term_field('slug', $q['tag'], 0, 'post_tag', 'db'); 
     1015                                $reqtag = is_term( $q['tag'], 'post_tag' ); 
     1016                                if ( !empty($reqtag) ) 
     1017                                        $reqtag = $reqtag['term_id']; 
     1018                                else 
     1019                                        $reqtag = 0; 
    9921020 
    993                         $q['tag_id'] = $reqtag; 
    994                         $q['tag__in'][] = $reqtag; 
     1021                                $q['tag_id'] = $reqtag; 
     1022                                $q['tag__in'][] = $reqtag; 
     1023                        } 
    9951024                } 
    9961025 
    997                 if ( !empty($q['tag__in']) || !empty($q['tag__not_in']) || !empty($q['tag__and']) ) { 
     1026                if ( !empty($q['tag__in']) || !empty($q['tag__not_in']) || !empty($q['tag__and']) || 
     1027                        !empty($q['tag_slug__in']) || !empty($q['tag_slug__and']) ) { 
    9981028                        $groupby = "{$wpdb->posts}.ID"; 
    9991029                } 
    10001030 
     
    10051035                        $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_tags) "; 
    10061036                } 
    10071037 
     1038                if ( !empty($q['tag_slug__in']) ) { 
     1039                        $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) LEFT JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) "; 
     1040                        $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' "; 
     1041                        $include_tags = "'" . implode("', '", $q['tag_slug__in']) . "'"; 
     1042                        $whichcat .= " AND $wpdb->terms.slug IN ($include_tags) "; 
     1043                } 
     1044 
    10081045                if ( !empty($q['tag__not_in']) ) { 
    10091046                        $ids = get_objects_in_term($q['tag__not_in'], 'post_tag'); 
    10101047                        if ( is_array($ids) && count($ids > 0) ) { 
     
    10131050                        } 
    10141051                } 
    10151052 
    1016                 if ( !empty($q['tag__and']) ) { 
     1053                if ( !empty($q['tag_slug__and']) ) { 
    10171054                        $count = 0; 
    1018                         foreach ( $q['tag__and'] as $tag_and ) { 
    1019                                 $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) "; 
    1020                                 $whichcat .= " AND tt$count.term_id = '$tag_and' "; 
     1055                        foreach ( $q['tag_slug__and'] as $tag_and ) { 
     1056                                $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) "; 
     1057                                $whichcat .= " AND term$count.slug = '$tag_and' "; 
    10211058                                $count++; 
    10221059                        } 
    10231060                } 
  • wp-includes/classes.php

    old new  
    33class WP { 
    44        var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'tag_id', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots'); 
    55 
    6         var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and'); 
     6        var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and'); 
    77        var $extra_query_vars = array(); 
    88 
    99        var $query_vars;