WordPress.org

Make WordPress Core

Ticket #21309: get_the_terms.21309.diff

File get_the_terms.21309.diff, 1.5 KB (added by scribu, 6 years ago)
  • wp-includes/category-template.php

    commit f5ea77aaef460b2a28b75e6446b58020b58805c2
    Author: scribu <mail@scribu.net>
    Date:   Sat Sep 22 19:48:51 2012 +0300
    
        use get_the_terms() in WP_Post->__get()
    
    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..a49d2cf 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