mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
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:
parent
c2fd99fd56
commit
5ed843d6d8
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,6 @@ $wp_version = '2.4-bleeding';
|
||||
*
|
||||
* @global int $wp_db_version
|
||||
*/
|
||||
$wp_db_version = 6825;
|
||||
$wp_db_version = 6846;
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user