WordPress.org

Make WordPress Core

Changeset 16056


Ignore:
Timestamp:
10/28/10 17:55:30 (7 years ago)
Author:
scribu
Message:

Add terms_clauses filter. Props sc0ttkclark for initial patch. See #15020

File:
1 edited

Legend:

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

    r15929 r16056  
    919919    } 
    920920 
    921     $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; 
    922  
    923921    $defaults = array('orderby' => 'name', 'order' => 'ASC', 
    924922        'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 
     
    942940        $args['pad_counts'] = false; 
    943941    } 
     942 
    944943    extract($args, EXTR_SKIP); 
    945944 
     
    992991        $order = ''; 
    993992 
    994     $where = ''; 
     993    $where = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')"; 
    995994    $inclusions = ''; 
    996995    if ( !empty($include) ) { 
     
    10591058    if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) { 
    10601059        if ( $offset ) 
    1061             $limit = 'LIMIT ' . $offset . ',' . $number; 
     1060            $limits = 'LIMIT ' . $offset . ',' . $number; 
    10621061        else 
    1063             $limit = 'LIMIT ' . $number; 
     1062            $limits = 'LIMIT ' . $number; 
    10641063    } else { 
    1065         $limit = ''; 
     1064        $limits = ''; 
    10661065    } 
    10671066 
     
    10881087            $selects = array('COUNT(*)'); 
    10891088    } 
    1090     $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 
    1091  
    1092     $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where $orderby $order $limit"; 
     1089 
     1090    $_fields = $fields; 
     1091 
     1092    $fields = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 
     1093 
     1094    $join = "INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; 
     1095 
     1096    $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); 
     1097    $clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args ); 
     1098    foreach ( $pieces as $piece ) 
     1099        $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 
     1100 
     1101    $query = "SELECT $fields FROM $wpdb->terms AS t $join WHERE $where $orderby $order $limits";     
     1102 
     1103    $fields = $_fields; 
    10931104 
    10941105    if ( 'count' == $fields ) { 
Note: See TracChangeset for help on using the changeset viewer.