Add get_terms() and get_term(). Move more of tagging to taxonomy. see #4189

git-svn-id: https://develop.svn.wordpress.org/trunk@5521 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2007-05-23 03:57:20 +00:00
parent 759b2afb2a
commit 0bc2a4b956
5 changed files with 137 additions and 84 deletions
+1 -59
View File
@@ -353,71 +353,13 @@ function _get_category_hierarchy() {
function &get_tags($args = '') {
global $wpdb, $category_links;
$defaults = array('orderby' => 'name', 'order' => 'ASC',
'hide_empty' => true, 'exclude' => '', 'include' => '',
'number' => '');
$args = wp_parse_args( $args, $defaults );
if ( 'count' == $args['orderby'] )
$args['orderby'] = 'tag_count';
else
$args['orderby'] = "cat_" . $args['orderby']; // restricts order by to cat_ID and cat_name fields
$args['number'] = (int) $args['number'];
extract($args);
$key = md5( serialize( $args ) );
if ( $cache = wp_cache_get( 'get_tags', 'category' ) )
if ( isset( $cache[ $key ] ) )
return apply_filters('get_tags', $cache[$key], $args);
$where = 'cat_ID > 0';
$inclusions = '';
if ( !empty($include) ) {
$child_of = 0; //ignore child_of and exclude params if using include
$exclude = '';
$incategories = preg_split('/[\s,]+/',$include);
if ( count($incategories) ) {
foreach ( $incategories as $incat ) {
if (empty($inclusions))
$inclusions = ' AND ( cat_ID = ' . intval($incat) . ' ';
else
$inclusions .= ' OR cat_ID = ' . intval($incat) . ' ';
}
}
}
if (!empty($inclusions))
$inclusions .= ')';
$where .= $inclusions;
$exclusions = '';
if ( !empty($exclude) ) {
$excategories = preg_split('/[\s,]+/',$exclude);
if ( count($excategories) ) {
foreach ( $excategories as $excat ) {
if (empty($exclusions))
$exclusions = ' AND ( cat_ID <> ' . intval($excat) . ' ';
else
$exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
}
}
}
if (!empty($exclusions))
$exclusions .= ')';
$exclusions = apply_filters('list_tags_exclusions', $exclusions, $args );
$where .= $exclusions;
if ( $hide_empty )
$where .= ' AND tag_count > 0';
$where .= ' AND ( type & ' . TAXONOMY_TAG . ' != 0 ) ';
if ( !empty($number) )
$number = 'LIMIT ' . $number;
else
$number = '';
$tags = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE $where ORDER BY $orderby $order $number");
$tags = get_terms('post_tag');
if ( empty($tags) )
return array();