WordPress.org

Make WordPress Core

Ticket #9547: #9547-sw2.2.diff

File #9547-sw2.2.diff, 2.7 KB (added by simonwheatley, 21 months ago)

Add ordering to term template tags through $args array type param (removed error_log call, var_dump, corrected the_terms args param)

  • wp-includes/category-template.php

     
    10541054 * 
    10551055 * @since 2.5.0 
    10561056 * 
     1057 * @see wp_get_object_terms() for reference on the $args param 
     1058 * 
    10571059 * @param int $id Post ID. 
    10581060 * @param string $taxonomy Taxonomy name. 
     1061 * @param array $args Accepts the same arguments as the $args param for wp_get_object_terms. 
    10591062 * @return array|bool False on failure. Array of term objects on success. 
    10601063 */ 
    1061 function get_the_terms( $id, $taxonomy ) { 
     1064function get_the_terms( $id, $taxonomy, $args = array() ) { 
    10621065        global $post; 
    10631066 
    10641067        $id = (int) $id; 
     
    10701073                        $id = (int) $post->ID; 
    10711074        } 
    10721075 
    1073         $terms = get_object_term_cache( $id, $taxonomy ); 
     1076        $cache_key = "{$taxonomy}_relationships_" . md5( serialize( $args ) ); 
     1077        $terms = wp_cache_get($id, $cache_key); 
     1078 
    10741079        if ( false === $terms ) { 
    1075                 $terms = wp_get_object_terms( $id, $taxonomy ); 
    1076                 wp_cache_add($id, $terms, $taxonomy . '_relationships'); 
     1080                $terms = wp_get_object_terms( $id, $taxonomy, $args ); 
     1081                wp_cache_add($id, $terms, $cache_key); 
    10771082        } 
    10781083 
    10791084        $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy ); 
     
    10891094 * 
    10901095 * @since 2.5.0 
    10911096 * 
     1097 * @see wp_get_object_terms() for reference on the $args param 
     1098 * 
    10921099 * @param int $id Post ID. 
    10931100 * @param string $taxonomy Taxonomy name. 
    10941101 * @param string $before Optional. Before list. 
    10951102 * @param string $sep Optional. Separate items using this. 
    10961103 * @param string $after Optional. After list. 
     1104 * @param array $args Accepts the same arguments as the $args param for wp_get_object_terms. 
    10971105 * @return string 
    10981106 */ 
    1099 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { 
    1100         $terms = get_the_terms( $id, $taxonomy ); 
     1107function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '', $args = array() ) { 
     1108        $terms = get_the_terms( $id, $taxonomy, $args ); 
    11011109 
    11021110        if ( is_wp_error( $terms ) ) 
    11031111                return $terms; 
     
    11271135 * @param string $before Optional. Before list. 
    11281136 * @param string $sep Optional. Separate items using this. 
    11291137 * @param string $after Optional. After list. 
     1138 * @param array $args Accepts the same arguments as the $args param for wp_get_object_terms. 
    11301139 * @return null|bool False on WordPress error. Returns null when displaying. 
    11311140 */ 
    1132 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { 
    1133         $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); 
     1141function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '', $args = array() ) { 
     1142        $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after, $args ); 
    11341143 
    11351144        if ( is_wp_error( $term_list ) ) 
    11361145                return false;