Opened 12 years ago
Closed 12 years ago
#20243 closed enhancement (wontfix)
Ability to disable multiple term URL queries
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | close |
Focuses: | Cc: |
Description
Sometimes site architecture demand is not to showing pages with multiple terms of taxonomy (not to showing two or more categories for posts, or not to showing two or more post tags, for example) in one archive pages. It is because this is bad for SEO (Search Engine Optimization) in some cases, and it is bad if archive pages with multiple terms of taxonomy be found in search engine result page. In some cases these pages can be indexed by google and sometimes (but not always) it is bad for site architecture.
So, “wrong” pages may be something like:
http://example.com/?cat=1,2
http://example.com/?cat=2,-5
http://example.com/category/cat1+cat2/
http://example.com/{custom-taxonomy}/{term1}+{term2}/
...and so on.
But needed only:
http://example.com/?cat=1
http://example.com/?cat=2
http://example.com/?cat=5
http://example.com/category/cat1/
http://example.com/category/cat2/
http://example.com/{custom-taxonomy}/{term1}
http://example.com/{custom-taxonomy}/{term2}
…and so on. In examples I want to get all children terms also.
I propose to use new variable (named WP_Query::single_term or similar ) in WP_Query class to state whether multiple terms of taxonomy in URL or not. So I can use code like this:
global $wp_query; if ($wp_query->single_term == TRUE ) { //Fine. All is correct for my site. Go on. } elseif ($wp_query->single_term == FALSE ) { //May be not fine. It is page with multiple terms or similar. I have no template for this case and my site architecture don’t allow pages with multiple terms in URL. I must return page 404 or redirect to another page. }
Change History (4)
#1
@
12 years ago
- Summary changed from New variable in WP_query class to state URLs for archive pages have multiple terms to Ability to disable multiple term URL queries
#2
@
12 years ago
- Keywords close added
That said, I don't think we need to burden Core with yet another flag.
You have multiple ways of achieving the desired outcome through a plugin. One example:
function disable_complex_term_queries( $args ) { foreach ( array( 'cat', 'tag' ) as $key ) { if ( isset( $args[$key] ) && false !== strpos( $args[$key], ',' ) ) return array( 'error' => '404' ); } return $args; } add_filter( 'request', 'disable_complex_term_queries' );
If we were to do this, WP_Query would not be the correct place, since it's responsible for all post queries, not just for queries coming from URLs.
So, the right place would be the WP class.