#12659 closed enhancement (fixed)
Hierarchical Taxonomy URL's do not include parent terms
Reported by: | dd32 | Owned by: | scribu |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Taxonomy | Keywords: | needs-patch |
Focuses: | Cc: |
Description
I just noticed that for all custom taxonomies, the url format is /base/slug/ - the same as tags.
Surely for hierarchical taxonomies, it makes more sense to do /base/parentslug/childslug/ ? Much like categories.
Setting to 3.1 milestone as its not a regression from a previous release. With the hierarchical taxonomies exposed in 3.0 however, this could become a quickly asked question why it doesnt operate like categories.
Attachments (1)
Change History (38)
#9
follow-up:
↓ 10
@
14 years ago
For back-compat issues, I'm thinking that this should be turned on by a specific flag in register_taxonomy(), 'hierarchical_uri' or similar?
Some of us have already implemented this using custom code, as well as there being links out there at present which would cause canonical redirections if it was made default.
#10
in reply to:
↑ 9
@
14 years ago
Replying to dd32:
For back-compat issues, I'm thinking that this should be turned on by a specific flag in register_taxonomy(), 'hierarchical_uri' or similar?
Makes sense to me.
#12
@
14 years ago
- Keywords has-patch needs-testing added; needs-patch removed
attachment 12659.diff added
- Initial run
- Non-optimized
- Causes multiple repeditive queries (May just be showing that Taxonomy-related queries are not always cached)
- Implements Canonicalisation as well
In order to test this, you'll need to register a taxonomy as such, AND flush your rewrite rules:
register_taxonomy('state', array('post'), array('hierarchical' => true, 'hierarchical_uri' => true, 'label' => 'States', 'singular_label' => 'State', 'show_ui' => true, 'query_var' => 'state', 'rewrite' => true) ); global $wp_rewrite; $wp_rewrite->flush_rules();
URL previously: http://localhost/wordpress-commit/state/kyogle/ After: http://localhost/wordpress-commit/state/au/nsw/kyogle/
#14
@
14 years ago
Wouldn't it be better if hierarchical_url was an option inside the 'rewrite' arg?
#15
@
14 years ago
Wouldn't it be better if hierarchical_url was an option inside the 'rewrite' arg?
I like the way you think.
#18
@
14 years ago
Shall we move hierarchical_url() under rewrite?
It's coming, I've got a conflict between it and another tax rewrite item right now, I'll have some time this weekend to tidy it up
#19
@
14 years ago
See [15824] Move hierarchical_url to $argsrewrite?hierarchical?
Note: This broke sub-category querying, I'm aware of this, I'm working on another patch to address rewrite items.
#22
@
14 years ago
- Keywords needs-patch added; has-patch needs-testing removed
[15825] introduces this notice when viewing a category page:
Notice: Undefined index: taxonomy in /home/cristi/svn/wp/wp-includes/query.php on line 1469:
if ( $taxonomy == $q['taxonomy'] ) $q['term'] = basename($q['term']);
I don't think those lines should be there at all.
Either we set 'taxonomy' and 'term' consistently, for all taxonomies, or we don't bother and encourage devs to use $wp_query->get_queried_object() to retrieve that information.
#23
@
14 years ago
Actually, that will always be false, since it's in the else branch of !empty($q['taxonomy'])
#25
@
14 years ago
[15825] introduces this notice when viewing a category page:
That code was there to prevent notices on custom taxonomy pages, Since it was inserted, It seems another commit has caused $q['taxonomy']
to be unset.
If code such as this is used on a generic template:
$link = get_term_link(get_query_var('term'), get_query_var('taxonomy'));
that'll cause one or the other not to be set.
wp_title()
also uses it:
// If there's a taxonomy if ( is_tax() ) { $tax = get_taxonomy( get_query_var('taxonomy') ); $title = single_term_title( $tax->labels->name . $t_sep, false ); }
While it may not be the "best" way of getting the data, That's how it's currently done in many themes that I've seen. Supporting $term and $taxonomy for backwards compatibility has to happen, Even if it's only the first taxonomy/term which is being queried on a multi-taxonomy query.
#27
@
14 years ago
@dd32 is going to be on vacation for the next two weeks. Does someone else want to pick this up and get it finished before freeze so it makes 3.1?
#28
@
14 years ago
The majority of this is already in, I'll leave the back-compat of the term/taxonomy query vars to Scribu however as he's done the majority of the work with the taxonomy query vars of late.
#29
@
14 years ago
The majority of this is already in
Meaning, As long as no bugs crop up in testing, This should be good to go.
#31
@
14 years ago
I added these patches to a test site and they work for the taxonomies themselves but posts still have permalinks of post-type/post-name, instead of post-type/terms/post-name/.
Also noticed that part of this patch is in the Nightly build, but not only does it not work but part of the patch is missing.
#32
@
14 years ago
I added these patches to a test site and they work for the taxonomies themselves but posts still have permalinks of post-type/post-name, instead of post-type/terms/post-name/.
That's the expected format. post-type url's are post_type/parent_post-name/post-name/ if set as hierarchical. This affects Taxonomy archives, such as /state/usa/california/ (Previously, would've just been /state/california/)
Also noticed that part of this patch is in the Nightly build, but not only does it not work but part of the patch is missing.
Feel like expanding on that a bit more? what's missing?
#34
@
14 years ago
Thanks for getting this fix in. I spent hours pulling my hair out thinking it was a param I was missing from register_taxonomy. Glad I'm not crazy. :-)
I've tested this on 3.1 beta and it works great.
'rewrite' => array( 'slug' => 'job-category', 'hierarchical' => true )
I was just about to report this.