Make WordPress Core

Changeset 6011


Ignore:
Timestamp:
09/03/2007 03:24:23 AM (17 years ago)
Author:
ryan
Message:

tagin, tagnot_in, and tag_and queries. fixes #4895

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r5920 r6011  
    22
    33class WP {
    4     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', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');
    5 
    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');
     4    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');
     5
     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');
    77    var $extra_query_vars = array();
    88
  • trunk/wp-includes/query.php

    r5944 r6011  
    406406            , 'category_name'
    407407            , 'tag'
     408            , 'tag_id'
    408409            , 'author_name'
    409410            , 'feed'
     
    419420        }
    420421
    421         $array_keys = array('category__in', 'category__not_in', 'category__and');
     422        $array_keys = array('category__in', 'category__not_in', 'category__and',
     423            'tag__in', 'tag__not_in', 'tag__and');
    422424       
    423425        foreach ( $array_keys as $key ) {
     
    582584            if (  '' != $qv['tag'] )
    583585                $this->is_tag = true;
     586
     587            $qv['tag__id'] = (int) $qv['tag__id'];
     588            if (  !empty($qv['tag__id']) )
     589                $this->is_tag = true;
     590
     591            if ( !is_array($qv['tag__in']) || empty($qv['tag__in']) ) {
     592                $qv['tag__in'] = array();
     593            } else {
     594                $qv['tag__in'] = array_map('intval', $qv['tag__in']);
     595                $this->is_tag = true;   
     596            }
     597
     598            if ( !is_array($qv['tag___not_in']) || empty($qv['tag__not_in']) ) {
     599                $qv['tag__not_in'] = array();
     600            } else {
     601                $qv['tag__not_in'] = array_map('intval', $qv['tag__not_in']);
     602            }
     603
     604            if ( !is_array($qv['tag__and']) || empty($qv['tag__and']) ) {
     605                $qv['tag__and'] = array();
     606            } else {
     607                $qv['tag__and'] = array_map('intval', $qv['tag__and']);
     608                $this->is_category = true; 
     609            }
    584610
    585611            if ( empty($qv['author']) || ($qv['author'] == '0') ) {
     
    923949        }
    924950
    925         if ( '' != $q['tag'] ) {
    926             $reqtag = is_term( $q['tag'], 'post_tag' );
    927             if ( !empty($reqtag) )
    928                 $reqtag = $reqtag['term_id'];
    929             else
    930                 $reqtag = 0;
    931 
    932             $q['tag_id'] = $reqtag;
    933             $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) ";
    934             $whichcat = " AND $wpdb->term_taxonomy.term_id IN ({$q['tag_id']}) AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
    935             $groupby = "{$wpdb->posts}.ID";
    936         }
    937 
    938951        // Category stuff for nice URLs
    939952        if ( '' != $q['category_name'] ) {
     
    968981            $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)";
    969982            $groupby = "{$wpdb->posts}.ID";
     983        }
     984
     985        // Tags
     986        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;
     992
     993            $q['tag_id'] = $reqtag;
     994            $q['tag__in'][] = $reqtag;
     995        }
     996
     997        if ( !empty($q['tag__in']) || !empty($q['tag__not_in']) || !empty($q['tag__and']) ) {
     998            $groupby = "{$wpdb->posts}.ID";
     999        }
     1000
     1001        if ( !empty($q['tag__in']) ) {
     1002            $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) ";
     1003            $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
     1004            $include_tags = "'" . implode("', '", $q['tag__in']) . "'";
     1005            $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_tags) ";
     1006        }
     1007
     1008        if ( !empty($q['tag__not_in']) ) {
     1009            $ids = get_objects_in_term($q['tag__not_in'], 'post_tag');
     1010            if ( is_array($ids) && count($ids > 0) ) {
     1011                $out_posts = "'" . implode("', '", $ids) . "'";
     1012                $whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
     1013            }
     1014        }
     1015
     1016        if ( !empty($q['tag__and']) ) {
     1017            $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' ";
     1021                $count++;
     1022            }
    9701023        }
    9711024
Note: See TracChangeset for help on using the changeset viewer.