Ticket #21309: get_the_terms.21309.diff

File get_the_terms.21309.diff, 1.5 KB (added by scribu, 8 months ago)
Line 
1commit f5ea77aaef460b2a28b75e6446b58020b58805c2
2Author: scribu <mail@scribu.net>
3Date:   Sat Sep 22 19:48:51 2012 +0300
4
5    use get_the_terms() in WP_Post->__get()
6
7diff --git wp-includes/category-template.php wp-includes/category-template.php
8index c4ba37d..fea6979 100644
9--- wp-includes/category-template.php
10+++ wp-includes/category-template.php
11@@ -1062,6 +1062,9 @@ function get_the_terms( $post, $taxonomy ) {
12        if ( ! $post = get_post( $post ) )
13                return false;
14 
15+       if ( !is_object_in_taxonomy( $post->post_type, $taxonomy ) )
16+               return false;
17+
18        $terms = get_object_term_cache( $post->ID, $taxonomy );
19        if ( false === $terms ) {
20                $terms = wp_get_object_terms( $post->ID, $taxonomy );
21diff --git wp-includes/post.php wp-includes/post.php
22index cac125e..a49d2cf 100644
23--- wp-includes/post.php
24+++ wp-includes/post.php
25@@ -495,17 +495,19 @@ final class WP_Post {
26                }
27 
28                if ( 'post_category' == $key ) {
29-                       if ( is_object_in_taxonomy( $this->post_type, 'category' ) )
30-                               return wp_get_post_categories( $this->ID );
31-                       else
32+                       $terms = get_the_terms( $this, 'category' );
33+                       if ( !$terms )
34                                return array();
35+
36+                       return wp_list_pluck( $terms, 'term_id' );
37                }
38 
39                if ( 'tags_input' == $key ) {
40-                       if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) )
41-                               return wp_get_post_tags( $this->ID, array( 'fields' => 'names' ) );
42-                       else
43+                       $terms = get_the_terms( $this, 'post_tag' );
44+                       if ( !$terms )
45                                return array();
46+
47+                       return wp_list_pluck( $terms, 'name' );
48                }
49 
50                // Rest of the values need filtering