Ticket #19705: better-tax-syntax.diff
| File better-tax-syntax.diff, 2.6 KB (added by misterbisson, 18 months ago) |
|---|
-
wp-includes/query.php
1699 1699 } 1700 1700 1701 1701 foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) { 1702 if ( 'post_tag' == $taxonomy )1703 continue; // Handled further down in the $q['tag'] block1702 // if ( 'post_tag' == $taxonomy ) 1703 // continue; // Handled further down in the $q['tag'] block 1704 1704 1705 1705 if ( $t->query_var && !empty( $q[$t->query_var] ) ) { 1706 1706 $tax_query_defaults = array( … … 1714 1714 1715 1715 $term = $q[$t->query_var]; 1716 1716 1717 if ( strpos($term, '+') !== false ) { 1718 $terms = preg_split( '/[+]+/', $term ); 1719 foreach ( $terms as $term ) { 1720 $tax_query[] = array_merge( $tax_query_defaults, array( 1721 'terms' => array( $term ) 1722 ) ); 1723 } 1724 } else { 1717 // determine the logical operator for each term 1718 $term_in_array = $term_and_array = $term_not_in_array = array(); 1719 foreach( (array) preg_split( '/[,]+/', $term ) as $partial ) 1720 { 1721 switch( $partial{0} ) 1722 { 1723 case '+': // the term is required 1724 $term_and_array[] = substr( $partial , 1 ); 1725 break; 1726 1727 case '-': // the term is excluded 1728 $term_not_in_array[] = substr( $partial , 1 ); 1729 break; 1730 1731 default: 1732 if ( strpos( $partial, '+' ) !== false ) // handle old-style AND syntax 1733 { 1734 $terms = preg_split( '/[+]+/', $partial ); 1735 foreach ( $terms as $partial ) 1736 $term_and_array[] = $partial; 1737 } else { 1738 $term_in_array[] = $partial; 1739 } 1740 } // end switch $partial{0} 1741 } 1742 1743 // add the above terms to the query array 1744 if( ! empty( $term_and_array )) 1745 { 1725 1746 $tax_query[] = array_merge( $tax_query_defaults, array( 1726 'terms' => preg_split( '/[,]+/', $term ) 1727 ) ); 1747 'terms' => $term_and_array, 1748 'operator' => 'AND', 1749 )); 1728 1750 } 1751 1752 if( ! empty( $term_not_in_array )) 1753 { 1754 $tax_query[] = array_merge( $tax_query_defaults, array( 1755 'terms' => $term_not_in_array, 1756 'operator' => 'NOT IN', 1757 )); 1758 } 1759 1760 if( ! empty( $term_in_array )) 1761 { 1762 $tax_query[] = array_merge( $tax_query_defaults, array( 1763 'terms' => $term_in_array, 1764 'operator' => 'IN', 1765 )); 1766 } 1767 1729 1768 } 1730 1769 } 1731 1770 … … 1782 1821 'include_children' => false 1783 1822 ); 1784 1823 } 1785 1824 /* 1786 1825 // Tag stuff 1787 1826 if ( '' != $q['tag'] && !$this->is_singular && $this->query_vars_changed ) { 1788 1827 if ( strpos($q['tag'], ',') !== false ) { … … 1855 1894 'operator' => 'AND' 1856 1895 ); 1857 1896 } 1897 */ 1858 1898 1859 1899 $this->tax_query = new WP_Tax_Query( $tax_query ); 1860 1900 }