Register taxonomies as object instead of arrays. Fix tt_ids query in get_post_terms().
git-svn-id: http://svn.automattic.com/wordpress/trunk@5567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e3f7055082
commit
965e63b970
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$wp_taxonomies =
|
$wp_taxonomies = array();
|
||||||
array('category' => array('object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count'),
|
$wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count');
|
||||||
'post_tag' => array('object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count'),
|
$wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count');
|
||||||
'link_category' => array('object_type' => 'link', 'hierarchical' => false));
|
$wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false);
|
||||||
|
|
||||||
|
//error_log(var_export($wp_taxonomies, true), 0);
|
||||||
function is_taxonomy( $taxonomy ) {
|
function is_taxonomy( $taxonomy ) {
|
||||||
global $wp_taxonomies;
|
global $wp_taxonomies;
|
||||||
|
|
||||||
|
@ -25,14 +26,18 @@ function is_taxonomy_hierarchical($taxonomy) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$taxonomy = get_taxonomy($taxonomy);
|
$taxonomy = get_taxonomy($taxonomy);
|
||||||
return $taxonomy['hierarchical'];
|
return $taxonomy->hierarchical;
|
||||||
}
|
}
|
||||||
|
|
||||||
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
||||||
global $wp_taxonomies;
|
global $wp_taxonomies;
|
||||||
|
|
||||||
|
$defaults = array('hierarchical' => false, 'update_count_callback' => '');
|
||||||
|
$args = wp_parse_args($args, $defaults);
|
||||||
|
|
||||||
|
$args['name'] = $taxonomy;
|
||||||
$args['object_type'] = $object_type;
|
$args['object_type'] = $object_type;
|
||||||
$wp_taxonomies[$taxonomy] = $args;
|
$wp_taxonomies[$taxonomy] = (object) $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_count_terms( $taxonomy ) {
|
function wp_count_terms( $taxonomy ) {
|
||||||
|
@ -259,8 +264,8 @@ function wp_update_term_count( $terms, $taxonomy ) {
|
||||||
$terms = array_map('intval', $terms);
|
$terms = array_map('intval', $terms);
|
||||||
|
|
||||||
$taxonomy = get_taxonomy($taxonomy);
|
$taxonomy = get_taxonomy($taxonomy);
|
||||||
if ( isset($taxonomy['update_count_callback']) )
|
if ( isset($taxonomy->update_count_callback) )
|
||||||
return call_user_func($taxonomy['update_count_callback'], $terms);
|
return call_user_func($taxonomy->update_count_callback, $terms);
|
||||||
|
|
||||||
// Default count updater
|
// Default count updater
|
||||||
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");
|
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");
|
||||||
|
@ -337,6 +342,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
|
||||||
$term_ids[] = $id['term_id'];
|
$term_ids[] = $id['term_id'];
|
||||||
$id = $id['term_taxonomy_id'];
|
$id = $id['term_taxonomy_id'];
|
||||||
$tt_ids[] = $id;
|
$tt_ids[] = $id;
|
||||||
|
|
||||||
if ( $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id = '$id'") )
|
if ( $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id = '$id'") )
|
||||||
continue;
|
continue;
|
||||||
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$object_id', '$id')");
|
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$object_id', '$id')");
|
||||||
|
@ -400,7 +406,7 @@ function get_object_terms($object_ids, $taxonomies, $args = array()) {
|
||||||
else if ( 'ids' == $fields )
|
else if ( 'ids' == $fields )
|
||||||
$taxonomy_data = $wpdb->get_col($query);
|
$taxonomy_data = $wpdb->get_col($query);
|
||||||
else if ( 'tt_ids' == $fields )
|
else if ( 'tt_ids' == $fields )
|
||||||
$taxonomy_data = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id IN ($object_ids) ORDER BY term_taxonomy_id $order");
|
$taxonomy_data = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order");
|
||||||
|
|
||||||
if ( ! $taxonomy_data )
|
if ( ! $taxonomy_data )
|
||||||
return array();
|
return array();
|
||||||
|
|
Loading…
Reference in New Issue