[wp-trac] [WordPress Trac] #18752: Allow category preference in permalinks

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 21 18:23:10 UTC 2012


#18752: Allow category preference in permalinks
------------------------------+------------------
 Reporter:  aaroncampbell     |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  3.5
Component:  General           |     Version:  3.2
 Severity:  normal            |  Resolution:
 Keywords:  has-patch commit  |
------------------------------+------------------

Comment (by nacin):

 Worth highlighting the canonical code for this:
 {{{
                 } elseif ( is_single() &&
 strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat =
 get_query_var( 'category_name' ) ) {
                         $category = get_category_by_path( $cat );
                         $post_terms =
 wp_get_object_terms($wp_query->get_queried_object_id(), 'category',
 array('fields' => 'tt_ids'));
                         if ( (!$category || is_wp_error($category)) || (
 !is_wp_error($post_terms) && !empty($post_terms) &&
 !in_array($category->term_taxonomy_id, $post_terms) ) )
                                 $redirect_url =
 get_permalink($wp_query->get_queried_object_id());
                 }
 }}}

 A good test would be what happens if you choose to use a category that
 isn't actually assigned to the post.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18752#comment:19>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list