Ticket #21309: get_the_terms.21309.2.diff

File get_the_terms.21309.2.diff, 2.5 KB (added by scribu, 8 months ago)
  • wp-includes/category-template.php

    diff --git wp-includes/category-template.php wp-includes/category-template.php
    index c4ba37d..fea6979 100644
    function get_the_terms( $post, $taxonomy ) { 
    10621062        if ( ! $post = get_post( $post ) ) 
    10631063                return false; 
    10641064 
     1065        if ( !is_object_in_taxonomy( $post->post_type, $taxonomy ) ) 
     1066                return false; 
     1067 
    10651068        $terms = get_object_term_cache( $post->ID, $taxonomy ); 
    10661069        if ( false === $terms ) { 
    10671070                $terms = wp_get_object_terms( $post->ID, $taxonomy ); 
  • wp-includes/post.php

    diff --git wp-includes/post.php wp-includes/post.php
    index cac125e..94e7447 100644
    final class WP_Post { 
    495495                } 
    496496 
    497497                if ( 'post_category' == $key ) { 
    498                         if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) 
    499                                 return wp_get_post_categories( $this->ID ); 
    500                         else 
     498                        $terms = get_the_terms( $this, 'category' ); 
     499                        if ( !$terms ) 
    501500                                return array(); 
     501 
     502                        return wp_list_pluck( $terms, 'term_id' ); 
    502503                } 
    503504 
    504505                if ( 'tags_input' == $key ) { 
    505                         if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) 
    506                                 return wp_get_post_tags( $this->ID, array( 'fields' => 'names' ) ); 
    507                         else 
     506                        $terms = get_the_terms( $this, 'post_tag' ); 
     507                        if ( !$terms ) 
    508508                                return array(); 
     509 
     510                        return wp_list_pluck( $terms, 'name' ); 
    509511                } 
    510512 
    511513                // Rest of the values need filtering 
    function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a 
    30433045        // Hierarchical taxonomies must always pass IDs rather than names so that children with the same 
    30443046        // names but different parents aren't confused. 
    30453047        if ( is_taxonomy_hierarchical( $taxonomy ) ) { 
    3046                 $tags = array_map( 'intval', $tags ); 
    3047                 $tags = array_unique( $tags ); 
     3048                $tags = array_unique( array_map( 'intval', $tags ) ); 
    30483049        } 
    30493050 
    3050         return wp_set_object_terms($post_id, $tags, $taxonomy, $append); 
     3051        $r = wp_set_object_terms( $post_id, $tags, $taxonomy, $append ); 
     3052        if ( is_wp_error( $r ) ) 
     3053                return $r; 
     3054 
     3055        wp_cache_delete( $post_id, $taxonomy . '_relationships' ); 
     3056 
     3057        return $r; 
    30513058} 
    30523059 
    30533060/** 
    function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 
    30763083                return true; 
    30773084        } 
    30783085 
    3079         if ( !empty($post_categories) ) { 
    3080                 $post_categories = array_map('intval', $post_categories); 
    3081                 $post_categories = array_unique($post_categories); 
    3082         } 
    3083  
    3084         return wp_set_object_terms($post_ID, $post_categories, 'category'); 
     3086        return wp_set_post_terms($post_ID, $post_categories, 'category'); 
    30853087} 
    30863088 
    30873089/**