WordPress.org

Make WordPress Core

Ticket #9547: #9547-sw1.diff

File #9547-sw1.diff, 2.9 KB (added by simonwheatley, 6 years ago)

Add ordering to term template tags

  • wp-includes/category-template.php

     
    10561056 *
    10571057 * @param int $id Post ID.
    10581058 * @param string $taxonomy Taxonomy name.
     1059 * @param string $order Either 'ASC' or 'DESC', defaults to 'ASC'.
     1060 * @param string $orderby Either 'name' (default), 'slug', 'count', 'term_order', 'term_group' (as per wp_get_object_terms).
    10591061 * @return array|bool False on failure. Array of term objects on success.
    10601062 */
    1061 function get_the_terms( $id, $taxonomy ) {
     1063function get_the_terms( $id, $taxonomy, $order = null, $orderby = null ) {
    10621064        global $post;
    10631065
    10641066        $id = (int) $id;
     
    10701072                        $id = (int) $post->ID;
    10711073        }
    10721074
    1073         $terms = get_object_term_cache( $id, $taxonomy );
     1075        $cache_key = "{$taxonomy}_relationships_order_{$orderby}_{$order}";
     1076        $terms = wp_cache_get($id, $cache_key);
     1077
    10741078        if ( false === $terms ) {
    1075                 $terms = wp_get_object_terms( $id, $taxonomy );
    1076                 wp_cache_add($id, $terms, $taxonomy . '_relationships');
     1079                $terms = wp_get_object_terms( $id, $taxonomy, array( 'order' => $order, 'orderby' => $orderby ) );
     1080                wp_cache_add($id, $terms, $cache_key);
    10771081        }
    10781082
    10791083        $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy );
     
    10941098 * @param string $before Optional. Before list.
    10951099 * @param string $sep Optional. Separate items using this.
    10961100 * @param string $after Optional. After list.
     1101 * @param string $order Either 'ASC' or 'DESC', defaults to 'ASC'.
     1102 * @param string $orderby Either 'name' (default), 'slug', 'count', 'term_order', 'term_group' (as per wp_get_object_terms).
    10971103 * @return string
    10981104 */
    1099 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
    1100         $terms = get_the_terms( $id, $taxonomy );
     1105function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '', $order = null, $orderby = null ) {
     1106        $terms = get_the_terms( $id, $taxonomy, $order, $orderby );
    11011107
    11021108        if ( is_wp_error( $terms ) )
    11031109                return $terms;
     
    11271133 * @param string $before Optional. Before list.
    11281134 * @param string $sep Optional. Separate items using this.
    11291135 * @param string $after Optional. After list.
     1136 * @param string $order Either 'ASC' or 'DESC', defaults to 'ASC'.
     1137 * @param string $orderby Either 'name' (default), 'slug', 'count', 'term_order', 'term_group' (as per wp_get_object_terms).
    11301138 * @return null|bool False on WordPress error. Returns null when displaying.
    11311139 */
    1132 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
    1133         $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
     1140function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '', $order = null, $orderby = null ) {
     1141        $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after, $order, $orderby );
    11341142
    11351143        if ( is_wp_error( $term_list ) )
    11361144                return false;