Support ordering for term relationships. Props andy. fixes #5857

git-svn-id: http://svn.automattic.com/wordpress/trunk@6851 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-14 17:17:57 +00:00
parent c2fd99fd56
commit 5ed843d6d8
3 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,7 @@ CREATE TABLE $wpdb->term_taxonomy (
CREATE TABLE $wpdb->term_relationships (
object_id bigint(20) NOT NULL default 0,
term_taxonomy_id bigint(20) NOT NULL default 0,
term_order int(11) NOT NULL default 0,
PRIMARY KEY (object_id,term_taxonomy_id),
KEY term_taxonomy_id (term_taxonomy_id)
) $charset_collate;

View File

@ -1033,6 +1033,8 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {
$orderby = 't.slug';
else if ( 'term_group' == $orderby )
$orderby = 't.term_group';
else if ( 'term_order' == $orderby )
$orderby = 'tr.term_order';
else
$orderby = 't.term_id';
@ -1249,6 +1251,18 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
}
}
$t = get_taxonomy($taxonomy);
if ( ! $append && $t->sort ) {
$values = array();
$term_order = 0;
$final_term_ids = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
foreach ( $term_ids as $term_id )
if ( in_array($term_id, $final_term_ids) )
$values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $term_id, ++$term_order);
if ( $values )
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
}
return $tt_ids;
}

View File

@ -16,6 +16,6 @@ $wp_version = '2.4-bleeding';
*
* @global int $wp_db_version
*/
$wp_db_version = 6825;
$wp_db_version = 6846;
?>