Make WordPress Core


Ignore:
Timestamp:
09/04/2012 04:29:28 PM (14 years ago)
Author:
ryan
Message:

Use get_post() instead of global $post.
Make the $post argument to get_post() optional, defaulting to the current post in The Loop.

Props nacin
see #21309

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r20675 r21735  
    10551055 * @since 2.5.0
    10561056 *
    1057  * @param int $id Post ID.
     1057 * @param mixed $post Post ID or object.
    10581058 * @param string $taxonomy Taxonomy name.
    10591059 * @return array|bool False on failure. Array of term objects on success.
    10601060 */
    1061 function get_the_terms( $id, $taxonomy ) {
    1062     global $post;
    1063 
    1064     $id = (int) $id;
    1065 
    1066     if ( !$id ) {
    1067         if ( empty( $post->ID ) )
    1068             return false;
    1069         else
    1070             $id = (int) $post->ID;
    1071     }
    1072 
    1073     $terms = get_object_term_cache( $id, $taxonomy );
     1061function get_the_terms( $post, $taxonomy ) {
     1062    if ( ! $post = get_post( $post ) )
     1063        return false;
     1064
     1065    $terms = get_object_term_cache( $post->ID, $taxonomy );
    10741066    if ( false === $terms ) {
    1075         $terms = wp_get_object_terms( $id, $taxonomy );
    1076         wp_cache_add($id, $terms, $taxonomy . '_relationships');
    1077     }
    1078 
    1079     $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy );
     1067        $terms = wp_get_object_terms( $post->ID, $taxonomy );
     1068        wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
     1069    }
     1070
     1071    $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
    10801072
    10811073    if ( empty( $terms ) )
Note: See TracChangeset for help on using the changeset viewer.