Make WordPress Core

Changeset 37262


Ignore:
Timestamp:
04/20/2016 03:34:15 PM (8 years ago)
Author:
boonebgorges
Message:

Canonical: Use get_the_terms() to verify that a post belongs to the requested %category%.

The get_the_terms() wrapper provides cache support, and saves a database hit
on sites with a persistent cache backend.

Props spacedmonkey.
Fixes #36602.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r36237 r37262  
    257257        } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) {
    258258            $category = get_category_by_path( $cat );
    259             $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
    260             if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
     259            $post_terms = get_the_terms( $wp_query->get_queried_object_id(), 'category' );
     260            if ( ( ! $category || is_wp_error( $category ) ) || ( ! is_wp_error( $post_terms ) && ! empty( $post_terms ) && ! in_array( $category, $post_terms ) ) ) {
    261261                $redirect_url = get_permalink($wp_query->get_queried_object_id());
     262            }
    262263        }
    263264
Note: See TracChangeset for help on using the changeset viewer.