Make WordPress Core


Ignore:
Timestamp:
02/21/2012 07:00:06 PM (13 years ago)
Author:
duck_
Message:

Ensure that a category is part of the query before redirecting permalink structures containing %category%. Fixes #19241.

This fixes incorrect canonical redirects for singular queries using custom rewrite rules.

File:
1 edited

Legend:

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

    r19880 r19970  
    192192
    193193            }
    194         } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
    195             $category = get_category_by_path(get_query_var('category_name'));
     194        } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) {
     195            $category = get_category_by_path( $cat );
    196196            $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
    197197            if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
Note: See TracChangeset for help on using the changeset viewer.