Ambiguous get_queried_object()
-
Hi,
I have a custom post type (“knowledge”) archive page that I want to be filterable by taxonomy (“topic”) as well as a custom field (“type”). To hook up the custom field filtering I’m using
pre_get_posts
to add a meta_query. Since I only want this filtering to be available on this archive page, I first check that$query->is_main_query() == true && is_archive() && get_queried_object()->name == "knowledge"
.The problem I’ve encountered is that
get_queried_object()
returns the taxonomy object if “topic” is in the URL and the post type object of the archive otherwise. I think the underlying issue is that a query can satisfy bothis_archive
andis_tax
at the same time, soget_queried_object()
has no way of knowing which one I want.If I want the “topic” taxonomy to be publicly queryable, how can I reliably check the post type of an archive page?
- The topic ‘Ambiguous get_queried_object()’ is closed to new replies.