diff --git a/wp-admin/export.php b/wp-admin/export.php
index ea44d7c029..bf60bec3b7 100644
--- a/wp-admin/export.php
+++ b/wp-admin/export.php
@@ -61,14 +61,14 @@ if ( isset( $_GET['author'] ) && $_GET['author'] != 'all' ) {
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
-$categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id");
+$categories = (array) get_categories('get=all');
function wxr_missing_parents($categories) {
if ( !is_array($categories) || empty($categories) )
return array();
foreach ( $categories as $category )
- $parents[$category->cat_ID] = $category->category_parent;
+ $parents[$category->term_id] = $category->parent;
$parents = array_unique(array_diff($parents, array_keys($parents)));
@@ -79,7 +79,7 @@ function wxr_missing_parents($categories) {
}
while ( $parents = wxr_missing_parents($categories) ) {
- $found_parents = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories WHERE cat_ID IN (" . join(', ', $parents) . ")");
+ $found_parents = get_categories("include=" . join(', ', $parents));
if ( is_array($found_parents) && count($found_parents) )
$categories = array_merge($categories, $found_parents);
else
@@ -90,8 +90,8 @@ while ( $parents = wxr_missing_parents($categories) ) {
$pass = 0;
$passes = 1000 + count($categories);
while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
- if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
- $cats[$cat->cat_ID] = $cat;
+ if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
+ $cats[$cat->term_id] = $cat;
} else {
$categories[] = $cat;
}
@@ -110,17 +110,17 @@ function wxr_cdata($str) {
}
function wxr_cat_name($c) {
- if ( empty($c->cat_name) )
+ if ( empty($c->name) )
return;
- echo '' . wxr_cdata($c->cat_name) . '';
+ echo '' . wxr_cdata($c->name) . '';
}
function wxr_category_description($c) {
- if ( empty($c->category_description) )
+ if ( empty($c->description) )
return;
- echo '' . wxr_cdata($c->category_description) . '';
+ echo '' . wxr_cdata($c->description) . '';
}
print '\n";
@@ -163,7 +163,7 @@ print '\n";
http://wordpress.org/?v=
- category_nicename; ?>category_parent ? $cats[$c->category_parent]->cat_name : ''; ?>posts_private ? '1' : '0'; ?>links_private ? '1' : '0'; ?>
+ slug; ?>parent ? $cats[$c->parent]->name : ''; ?>
diff --git a/wp-admin/index.php b/wp-admin/index.php
index a3d3151451..b715c92378 100644
--- a/wp-admin/index.php
+++ b/wp-admin/index.php
@@ -101,14 +101,15 @@ foreach ($scheduled as $post) {
get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
-$numcats = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
+$numcats = wp_count_terms('category');
+$numtags = wp_count_terms('post_tag');
$post_str = sprintf(__ngettext('%1$s post', '%1$s posts', $numposts), number_format_i18n($numposts), 'edit.php');
$comm_str = sprintf(__ngettext('%1$s comment', '%1$s comments', $numcomms), number_format_i18n($numcomms), 'edit-comments.php');
$cat_str = sprintf(__ngettext('%1$s category', '%1$s categories', $numcats), number_format_i18n($numcats), 'categories.php');
?>
-
+
diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php
index 5807238251..00f2c80535 100644
--- a/wp-includes/deprecated.php
+++ b/wp-includes/deprecated.php
@@ -56,7 +56,7 @@ function start_wp() {
function the_category_ID($echo = true) {
// Grab the first cat in the list.
$categories = get_the_category();
- $cat = $categories[0]->cat_ID;
+ $cat = $categories[0]->term_id;
if ( $echo )
echo $cat;
@@ -217,12 +217,10 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '
',
$limit = -1, $show_updated = 0) {
global $wpdb;
$cat_id = -1;
- $results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
- if ($results) {
- foreach ($results as $result) {
- $cat_id = $result->cat_ID;
- }
- }
+ $cat = get_term_by('name', $cat_name, 'link_category');
+ if ( $cat )
+ $cat_id = $cat->term_id;
+
get_links($cat_id, $before, $after, $between, $show_images, $orderby,
$show_description, $show_rating, $limit, $show_updated);
}
@@ -235,10 +233,10 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '
',
function wp_get_linksbyname($category, $args = '') {
global $wpdb;
- $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category' LIMIT 1");
-
- if (! $cat_id)
- return;
+ $cat = get_term_by('name', $cat_name, 'link_category');
+ if ( !$cat )
+ return false;
+ $cat_id = $cat->term_id;
$args = add_query_arg('category', $cat_id, $args);
wp_get_links($args);
@@ -263,17 +261,13 @@ function wp_get_linksbyname($category, $args = '') {
** echo ''.$link->link_name.'';
** }
**/
-// Deprecate in favor of get_linkz().
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
global $wpdb;
$cat_id = -1;
- //$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
- // TODO: Fix me.
- if ($results) {
- foreach ($results as $result) {
- $cat_id = $result->cat_id;
- }
- }
+ $cat = get_term_by('name', $cat_name, 'link_category');
+ if ( $cat )
+ $cat_id = $cat->term_id;
+
return get_linkobjects($cat_id, $orderby, $limit);
}
@@ -313,41 +307,17 @@ function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit
** link_notes
**/
// Deprecate in favor of get_linkz().
-function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) {
+function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
global $wpdb;
- $sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
- if ($category != -1) {
- $sql .= " AND link_category = $category ";
- }
- if ($orderby == '')
- $orderby = 'id';
- if (substr($orderby,0,1) == '_') {
- $direction = ' DESC';
- $orderby = substr($orderby,1);
- }
- if (strcasecmp('rand',$orderby) == 0) {
- $orderby = 'rand()';
- } else {
- $orderby = " link_" . $orderby;
- }
- $sql .= ' ORDER BY ' . $orderby;
- $sql .= $direction;
- /* The next 2 lines implement LIMIT TO processing */
- if ($limit != -1)
- $sql .= " LIMIT $limit";
+ $links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
- $results = $wpdb->get_results($sql);
- if ($results) {
- foreach ($results as $result) {
- $result->link_url = $result->link_url;
- $result->link_name = $result->link_name;
- $result->link_description = $result->link_description;
- $result->link_notes = $result->link_notes;
- $newresults[] = $result;
- }
+ $links_array = array();
+ foreach ($links as $link) {
+ $links_array[] = $link;
}
- return $newresults;
+
+ return $links_array;
}
/** function get_linksbyname_withrating()
diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php
index 15a019fe18..585f0edc44 100644
--- a/wp-includes/general-template.php
+++ b/wp-includes/general-template.php
@@ -185,8 +185,9 @@ function wp_title($sep = '»', $display = true) {
else
$category_name = $category_name[count($category_name)-2]; // there was a trailling slash
}
- $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
- $title = apply_filters('single_cat_title', $title);
+ $cat = get_term_by('slug', $category_name, 'category');
+ if ( $cat )
+ $title = apply_filters('single_cat_title', $cat->name);
}
if ( !empty($tag) ) {
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
index 1d15d38b52..abf9538c59 100644
--- a/wp-includes/taxonomy.php
+++ b/wp-includes/taxonomy.php
@@ -35,6 +35,12 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$wp_taxonomies[$taxonomy] = $args;
}
+function wp_count_terms( $taxonomy ) {
+ global $wpdb;
+
+ return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy'");
+}
+
/**
* Adds a new term to the database. Optionally marks it as an alias of an existing term.
* @param int|string $term The term to add or update.