Make WordPress Core

Changeset 17244


Ignore:
Timestamp:
01/09/2011 04:19:48 PM (16 years ago)
Author:
ryan
Message:

categoryand, tagand, tag_slugin, tag_slugand support. fixes #16157

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r17243 r17244  
    16931693
    16941694                if ( !empty($q['category__in']) ) {
    1695                         $q['category__in'] = array_unique( $q['category__in'] );
     1695                        $q['category__in'] = array_map('absint', array_unique( $q['category__in'] ) );
    16961696                        $tax_query[] = array(
    16971697                                'taxonomy' => 'category',
    … …  
    17021702
    17031703                if ( !empty($q['category__not_in']) ) {
    1704                         $q['category__not_in'] = array_unique( $q['category__not_in'] );
     1704                        $q['category__not_in'] = array_map('absint', array_unique( $q['category__not_in'] ) );
    17051705                        $tax_query[] = array(
    17061706                                'taxonomy' => 'category',
    17071707                                'terms' => $q['category__not_in'],
    1708                                 'operator' => 'NOT IN',
     1708                                'operator' => 'NOT IN'
     1709                        );
     1710                }
     1711
     1712                if ( !empty($q['category__and']) ) {
     1713                        $q['category__and'] = array_map('absint', array_unique( $q['category__and'] ) );
     1714                        $tax_query[] = array(
     1715                                'taxonomy' => 'category',
     1716                                'terms' => $q['category__and'],
     1717                                'field' => 'term_id',
     1718                                'operator' => 'AND'
    17091719                        );
    17101720                }
    … …  
    17121722                // Tag stuff
    17131723                if ( !empty($q['tag_id']) ) {
     1724                        $q['tag_id'] = absint( $q['tag_id'] );
    17141725                        $tax_query[] = array(
    17151726                                'taxonomy' => 'post_tag',
    1716                                 'terms' => $q['tag_id'],
     1727                                'terms' => $q['tag_id']
    17171728                        );
    17181729                }
    17191730
    17201731                if ( !empty($q['tag__in']) ) {
     1732                        $q['tag__in'] = array_map('absint', array_unique( $q['tag__in'] ) );
    17211733                        $tax_query[] = array(
    17221734                                'taxonomy' => 'post_tag',
    1723                                 'terms' => $q['tag__in'],
     1735                                'terms' => $q['tag__in']
    17241736                        );
    17251737                }
    17261738
    17271739                if ( !empty($q['tag__not_in']) ) {
     1740                        $q['tag__not_in'] = array_map('absint', array_unique( $q['tag__not_in'] ) );
    17281741                        $tax_query[] = array(
    17291742                                'taxonomy' => 'post_tag',
    17301743                                'terms' => $q['tag__not_in'],
    1731                                 'operator' => 'NOT IN',
     1744                                'operator' => 'NOT IN'
     1745                        );
     1746                }
     1747
     1748                if ( !empty($q['tag__and']) ) {
     1749                        $q['tag__and'] = array_map('absint', array_unique( $q['tag__and'] ) );
     1750                        $tax_query[] = array(
     1751                                'taxonomy' => 'post_tag',
     1752                                'terms' => $q['tag__and'],
     1753                                'operator' => 'AND'
     1754                        );
     1755                }
     1756
     1757                if ( !empty($q['tag_slug__in']) ) {
     1758                        $q['tag_slug__in'] = array_map('sanitize_title', $q['tag_slug__in']);
     1759                        $tax_query[] = array(
     1760                                'taxonomy' => 'post_tag',
     1761                                'terms' => $q['tag_slug__in'],
     1762                                'field' => 'slug'
     1763                        );
     1764                }
     1765
     1766                if ( !empty($q['tag_slug__and']) ) {
     1767                        $q['tag_slug__and'] = array_map('sanitize_title', $q['tag_slug__and']);
     1768                        $tax_query[] = array(
     1769                                'taxonomy' => 'post_tag',
     1770                                'terms' => $q['tag_slug__and'],
     1771                                'field' => 'slug',
     1772                                'operator' => 'AND'
    17321773                        );
    17331774                }
  • trunk/wp-includes/taxonomy.php

    r17240 r17244  
    672672
    673673                                $where[] = "$alias.term_taxonomy_id $operator ($terms)";
    674                         }
    675                         elseif ( 'NOT IN' == $operator ) {
     674                        } elseif ( 'NOT IN' == $operator ) {
    676675
    677676                                if ( empty( $terms ) )
    … …  
    684683                                        FROM $wpdb->term_relationships
    685684                                        WHERE term_taxonomy_id IN ($terms)
     685                                )";
     686                        } elseif ( 'AND' == $operator ) {
     687
     688                                if ( empty( $terms ) )
     689                                        continue;
     690
     691                                $num_terms = count( $terms );
     692
     693                                $terms = implode( ',', $terms );
     694
     695                                $where[] = "$primary_table.$primary_id_column IN (
     696                                        SELECT object_id
     697                                        FROM $wpdb->term_relationships
     698                                        WHERE term_taxonomy_id IN ($terms)
     699                                        GROUP BY object_id HAVING COUNT(object_id) = $num_terms
    686700                                )";
    687701                        }
Note: See TracChangeset for help on using the changeset viewer.