WordPress.org

Make WordPress Core

Ticket #13471: 13471.diff

File 13471.diff, 966 bytes (added by blepoxp, 5 years ago)

Checks for multiple categories and only submits last category to get_term_by

  • wp-includes/canonical.php

     
    180180 
    181181                        } 
    182182                } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { 
    183                         $category = get_term_by('slug', get_query_var('category_name'), 'category'); 
     183                        $segment = explode( '/', get_query_var( 'category_name' ) ) ? end( explode( '/', get_query_var( 'category_name' ) ) ) : get_query_var( 'category_name' ); 
     184                        $category = get_term_by('slug', $segment, 'category'); 
    184185                        $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); 
    185186                        if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) 
    186187                                $redirect_url = get_permalink($wp_query->get_queried_object_id());