Make WordPress Core

Changeset 15732


Ignore:
Timestamp:
10/06/2010 11:04:03 AM (13 years ago)
Author:
scribu
Message:

Make hierarchical URLs work for any hierarchical taxonomy. See #12659

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r15731 r15732  
    14871487        $tax_query = array();
    14881488
    1489         if ( $this->is_tax ) {
    1490             foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
    1491                 if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
    1492                     $tax_query_defaults = array(
    1493                         'taxonomy' => $taxonomy,
    1494                         'field' => 'slug',
    1495                         'operator' => 'IN'
    1496                     );
    1497 
    1498                     $term = str_replace( ' ', '+', $q[$t->query_var] );
    1499 
    1500                     if ( strpos($term, '+') !== false ) {
    1501                         $terms = preg_split( '/[+\s]+/', $term );
    1502                         foreach ( $terms as $term ) {
    1503                             $tax_query[] = array_merge( $tax_query_defaults, array(
    1504                                 'terms' => array( $term )
    1505                             ) );
    1506                         }
    1507                     } else {
     1489        foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
     1490            if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
     1491                $tax_query_defaults = array(
     1492                    'taxonomy' => $taxonomy,
     1493                    'field' => 'slug',
     1494                    'operator' => 'IN'
     1495                );
     1496
     1497                $term = urlencode( urldecode( $q[$t->query_var] ) );
     1498
     1499                if ( $t->hierarchical_url ) {
     1500                    $tax_query[] = array_merge( $tax_query_defaults, array(
     1501                        'terms' => array( basename( str_replace( '%2F', '/', $term ) ) )
     1502                    ) );
     1503                } elseif ( strpos($term, '+') !== false ) {
     1504                    $terms = preg_split( '/[+\s]+/', $term );
     1505                    foreach ( $terms as $term ) {
    15081506                        $tax_query[] = array_merge( $tax_query_defaults, array(
    1509                             'terms' => preg_split('/[,\s]+/', $term)
     1507                            'terms' => array( $term )
    15101508                        ) );
    15111509                    }
     1510                } else {
     1511                    $tax_query[] = array_merge( $tax_query_defaults, array(
     1512                        'terms' => preg_split('/[,\s]+/', $term)
     1513                    ) );
    15121514                }
    15131515            }
     
    15501552                'operator' => 'NOT IN',
    15511553                'field' => 'term_id'
    1552             );
    1553         }
    1554 
    1555         // Category stuff for nice URLs
    1556         if ( '' != $q['category_name'] && !$this->is_singular ) {
    1557             $q['category_name'] = str_replace( '%2F', '/', urlencode(urldecode($q['category_name'])) );
    1558             $q['category_name'] = '/' . trim( $q['category_name'], '/' );
    1559 
    1560             $tax_query[] = array(
    1561                 'taxonomy' => 'category',
    1562                 'terms' => array( basename( $q['category_name'] ) ),
    1563                 'operator' => 'IN',
    1564                 'field' => 'slug'
    15651554            );
    15661555        }
  • trunk/wp-includes/taxonomy.php

    r15731 r15732  
    1818    register_taxonomy( 'category', 'post', array(
    1919        'hierarchical' => true,
     20        'hierarchical_url' => true,
    2021        'update_count_callback' => '_update_post_term_count',
    21         'query_var' => false,
     22        'query_var' => 'category_name',
    2223        'rewrite' => false,
    2324        'public' => true,
Note: See TracChangeset for help on using the changeset viewer.