From facc7245fa36db87be2a7a2cc3c42f46dbe2ace6 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 30 May 2007 01:05:44 +0000 Subject: [PATCH] Add ignore_empty option to wp_count_terms(). see #4189 git-svn-id: http://svn.automattic.com/wordpress/trunk@5596 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1a5aaafde3..5c776f273f 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -39,10 +39,18 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { $wp_taxonomies[$taxonomy] = (object) $args; } -function wp_count_terms( $taxonomy ) { +function wp_count_terms( $taxonomy, $args = array() ) { global $wpdb; - return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy'"); + $defaults = array('ignore_empty' => false); + $args = wp_parse_args($args, $defaults); + extract($args); + + $where = ''; + if ( $ignore_empty ) + $where = 'AND count > 0'; + + return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy' $where"); } /**