WordPress.org

Make WordPress Core

Ticket #19094: taxonomy.patch

File taxonomy.patch, 1.8 KB (added by Zatsugami, 4 years ago)

Taxonomy patch. New filters for wp_get_object_terms giving access to select query.

  • taxonomy.php

     
    19001900        else if ( 'all_with_object_id' == $fields ) 
    19011901                $select_this = 't.*, tt.*, tr.object_id'; 
    19021902 
    1903         $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 
     1903        $pieces = array( 'select', 'join', 'where', 'orderby', 'order' ); 
    19041904 
     1905        // Setting up initial $query pieces, some are already present 
     1906        $select = $select_this; 
     1907        $join   = "INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 
     1908        $where  = "WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids)"; 
     1909 
     1910        // We applay filters 
     1911        $select         = apply_filters( 'object_terms_select', $select ); 
     1912        $join           = apply_filters( 'object_terms_join', $join ); 
     1913        $where          = apply_filters( 'object_terms_where', $where ); 
     1914        $orderby        = apply_filters( 'object_terms_orderby', $orderby); 
     1915        $order          = apply_filters( 'object_terms_order', $order); 
     1916 
     1917        // Filter all clauses at once, for convenience 
     1918        $clauses = (array) apply_filters( 'object_terms_clauses', compact( $pieces ) ); 
     1919        foreach ( $pieces as $piece ) 
     1920                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 
     1921 
     1922        $query = "SELECT $select FROM $wpdb->terms AS t $join $where $orderby $order"; 
     1923 
     1924        $query = apply_filters('object_terms_query', $query); 
     1925 
    19051926        if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 
    19061927                $terms = array_merge($terms, $wpdb->get_results($query)); 
    19071928                update_term_cache($terms);