Ticket #15675: add-parent-arg-to-wp-get-object-terms.diff
| File add-parent-arg-to-wp-get-object-terms.diff, 6.0 KB (added by , 15 years ago) |
|---|
-
taxonomy.php
1498 1498 /** 1499 1499 * Will unlink the object from the taxonomy or taxonomies. 1500 1500 * 1501 * Will remove all relationships between the object and any terms in 1502 * a particular taxonomy or taxonomies. Does not remove the term or 1501 * Will remove all relationships between the object and any terms in 1502 * a particular taxonomy or taxonomies. Does not remove the term or 1503 1503 * taxonomy itself. 1504 1504 * 1505 1505 * @package WordPress … … 1613 1613 // Clean the relationship caches for all object types using this term 1614 1614 $tax_object = get_taxonomy( $taxonomy ); 1615 1615 foreach ( $tax_object->object_type as $object_type ) 1616 clean_object_term_cache( $objects, $object_type ); 1617 1616 clean_object_term_cache( $objects, $object_type ); 1617 1618 1618 do_action( 'delete_term_taxonomy', $tt_id ); 1619 1619 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $tt_id ) ); 1620 1620 do_action( 'deleted_term_taxonomy', $tt_id ); … … 1649 1649 * Retrieves the terms associated with the given object(s), in the supplied taxonomies. 1650 1650 * 1651 1651 * The following information has to do the $args parameter and for what can be 1652 * contained in the string or array of that parameter, if it exists. 1652 * contained in the string or array of that parameter, if it exists. The arguments 1653 * can be: 1653 1654 * 1654 * The first argument is called, 'orderby' and has the default value of 'name'.1655 * The other value that is supported is 'count'.1655 * 'orderby' The default value is 'name', and the other potential values are 1656 * 'count', 'slug', 'term_group','term_order' or 'none'. 1656 1657 * 1657 * The second argument is called, 'order' and has the default value of 'ASC'. 1658 * The only other value that will be acceptable is 'DESC'. 1658 * 'order' The default value of 'ASC', and the other acceptable value is 'DESC'. 1659 1659 * 1660 * The final argument supported is called, 'fields' and has the default value of 1661 * 'all'. There are multiple other options that can be used instead. Supported 1662 * values are as follows: 'all', 'ids', 'names', and finally 1663 * 'all_with_object_id'. 1660 * 'parent' There is no default value but if specified it should contain an integer 1661 * value corresponding to the value of the parent field to filter by. 1664 1662 * 1665 * The fields argument also decides what will be returned. If 'all' or 1666 * 'all_with_object_id' is choosen or the default kept intact, then all matching 1667 * terms objects will be returned. If either 'ids' or 'names' is used, then an 1668 * array of all matching term ids or term names will be returned respectively. 1663 * 'fields' The default value is 'all' with the other options supported being 1664 * 'all', 'ids', 'names', 'id=>name', 'id=>term', 'tt_ids' and 1665 * 'all_with_object_id'. 1669 1666 * 1667 * The fields argument also decides what will be returned. If the default is 1668 * used or either 'all' or 'all_with_object_id' is specified then all matching 1669 * terms objects will be returned. If either 'ids', 'tt_ids' or 'names' is used, 1670 * then an array of all matching term ids, undocumented (tt_ids) or term names 1671 * will be returned respectively. 1672 * 1673 * May return duplicate terms when when 'fields' equals 'all_with_object_id'. 1674 * 1670 1675 * @package WordPress 1671 1676 * @subpackage Taxonomy 1672 1677 * @since 2.3.0 … … 1746 1751 $select_this = 't.term_id'; 1747 1752 else if ( 'names' == $fields ) 1748 1753 $select_this = 't.name'; 1754 else if ( 'id=>name' == $fields ) 1755 $select_this = 't.term_id,t.name'; 1756 else if ( 'id=>term' == $fields ) 1757 $select_this = 't.*'; 1749 1758 else if ( 'all_with_object_id' == $fields ) 1750 1759 $select_this = 't.*, tt.*, tr.object_id'; 1751 1760 1752 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 1761 $where_parent = (empty($parent) ? '' : " tt.parent={$parent} AND"); 1762 $distinct = ('all_with_object_id' == $fields ? '' : ' DISTINCT'); 1753 1763 1754 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 1755 $terms = array_merge($terms, $wpdb->get_results($query)); 1756 update_term_cache($terms); 1757 } else if ( 'ids' == $fields || 'names' == $fields ) { 1758 $terms = array_merge($terms, $wpdb->get_col($query)); 1759 } else if ( 'tt_ids' == $fields ) { 1760 $terms = $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) $orderby $order"); 1764 if ( 'tt_ids' == $fields ) { 1765 $terms = $wpdb->get_col("SELECT{$distinct} 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{$where_parent} tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"); 1766 } else { 1767 $query = "SELECT{$distinct} DISTINCT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE{$where_parent} tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 1768 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 1769 $terms = array_merge($terms, $wpdb->get_results($query)); 1770 update_term_cache($terms); 1771 } else if ( 'ids' == $fields || 'names' == $fields ) { 1772 $terms = array_merge($terms, $wpdb->get_col($query)); 1773 } 1761 1774 } 1762 1775 1763 1776 if ( ! $terms ) 1764 1777 $terms = array(); 1765 1778 1779 if ( 'id=>name' == $fields ) { 1780 $_terms = array(); 1781 foreach($terms as $term) 1782 $_terms[$term->term_id] = $term->name; 1783 $terms = $_terms; 1784 } else if ( 'id=>term' == $fields ) { 1785 $_terms = array(); 1786 foreach($terms as $term) 1787 $_terms[$term->term_id] = $term; 1788 $terms = $_terms; 1789 } 1790 1766 1791 return apply_filters('wp_get_object_terms', $terms, $object_ids, $taxonomies, $args); 1767 1792 } 1768 1793