From 9f82f611dae3c3e10d2b3e054b48d60b48d98b5f Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 21 Apr 2009 22:13:44 +0000 Subject: [PATCH] get_terms_orderby, get_terms_fields, and tag_clooud-sort filters. Props jhodgdon, filosofo. fixes #9004 git-svn-id: http://svn.automattic.com/wordpress/trunk@11037 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 5 +++++ wp-includes/taxonomy.php | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index c204ba60f8..98c7080cc7 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -573,6 +573,9 @@ function default_topic_count_text( $count ) { * 'format' argument will format the tags in a UL HTML list. The array value for * the 'format' argument will return in PHP array type format. * + * The 'tag_cloud_sort' filter allows you to override the sorting done + * by the 'orderby' argument; passed to the filter: $tags array and $args array. + * * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or * 'RAND'. @@ -618,6 +621,8 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { else uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') ); + $tags = apply_filters( 'tag_cloud_sort', $tags, $args ); + if ( 'DESC' == $order ) $tags = array_reverse( $tags, true ); elseif ( 'RAND' == $order ) { diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index c3a5649ad8..46e01b52b8 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -526,6 +526,12 @@ function get_term_to_edit( $id, $taxonomy ) { * The 'list_terms_exclusions' filter passes the compiled exclusions along with * the $args. * + * The 'get_terms_orderby' filter passes the ORDER BY clause for the query + * along with the $args array. + + * The 'get_terms_fields' filter passes the fields for the SELECT query + * along with the $args array. + * * The list of arguments that $args can contain, which will overwrite the defaults: * * orderby - Default is 'name'. Can be name, count, or nothing (will use @@ -673,6 +679,7 @@ function &get_terms($taxonomies, $args = '') { $orderby = 't.term_group'; else $orderby = 't.term_id'; + $orderby = apply_filters( 'get_terms_orderby', $orderby, $args ); $where = ''; $inclusions = ''; @@ -757,13 +764,14 @@ function &get_terms($taxonomies, $args = '') { $where .= " AND (t.name LIKE '%$search%')"; } - $select_this = ''; + $selects = array(); if ( 'all' == $fields ) - $select_this = 't.*, tt.*'; + $selects = array('t.*', 'tt.*'); else if ( 'ids' == $fields ) - $select_this = 't.term_id, tt.parent, tt.count'; + $selects = array('t.term_id', 'tt.parent', 'tt.count'); else if ( 'names' == $fields ) - $select_this = 't.term_id, tt.parent, tt.count, t.name'; + $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); + $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); $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 ORDER BY $orderby $order $limit";