Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#20243 closed enhancement (wontfix)

Ability to disable multiple term URL queries

Reported by: egorpromo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: close
Focuses: Cc:


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:

...and so on.

But needed only:
…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 @scribu
6 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

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.

#2 @scribu
6 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' ); `

Version 0, edited 6 years ago by scribu (next)

#3 @duck_
6 years ago

wp-includes/canonical.php has another example around line 150. We count the number of terms in each tax query and check that the total is <= 1.

#4 @scribu
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.