Skip Navigation

[Resolved] Taxonomy archive is visible though the option "query_var" is unchecked

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Nigel 5 years ago.

Assisted by: Nigel.

Author
Posts
#1384091

Hi!

I setup an taxonomy for posts and unchecked the option "query_var" where it says in the description:

Disable to prevent queries like "mysite.com/?taxonomy=example". Enable to use queries like "mysite.com/?taxonomy=example".

The problem: I can still query taxonomy archives like mysite.com/?taxonomy=example&term=myterm

Why? I think this doens't work as aspected.

Best regards
Matthias

#1384237

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I think might arise because of some confusion with the description of the option.

You can see the option documented here: https://codex.wordpress.org/Function_Reference/register_taxonomy#Parameters (you'll need to scroll down to the query_var option itself).

If you have a taxonomy 'colour' with terms such as 'red', 'blue', etc., then that setting is for whether to allow queries such as

mysite.com/?colour=red or not

The example of mysite.com/?taxonomy=example is fairly meaningless because "taxonomy" is not what is used, it is the slug of the taxonomy that is used (or you can specify a different string in the settings).

When you add URL parameters that WordPress doesn't recognise it will simply ignore them, so if you enter mysite.com/?taxonomy=example, that will give the same result as typing just mysite.com/

#1384291
types-taxonomy-2.png
types-taxonomy-1.png

Hi Nigel,

thanks for your answer but I'm still confused.

In my example I have created a taxonomy "linksammlung" and added a term "super". I can view the archive of this term in the frontend with the URL hidden link. I thought the option "query_var" would prevent this. My goal is to hide all the archives of this taxonomy. The URL should show a 404.

Cheers,
Matthias

#1384513

This helped me: https://toolset.com/forums/topic/turn-off-custom-taxonomy-archive-pages/
To redirect to 404, us this:

function pabstwp_disable_custom_taxonomy_archive ( $query ) {
   if (($query->is_main_query()) && (is_tax( array('taxonomy1', 'taxonomy2', 'taxonomy3') ))) {
      $query->set_404();
   }
}
add_action( 'pre_get_posts', 'pabstwp_disable_custom_taxonomy_archive' );
#1385595

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Thanks for sharing that.

For the query you were describing, i.e. hidden link

then I think the relevant setting would be "publicly_queryable" not the query_var option, but looking it seems we don't include that option in the taxonomy settings.

I haven't noticed that before, so I'm reporting it anyway, just for your information.