Title: Ambiguous get_queried_object()
Last modified: August 30, 2016

---

# Ambiguous get_queried_object()

 *  [mslade](https://wordpress.org/support/users/mslade/)
 * (@mslade)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/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 both `is_archive` and`
   is_tax` at the same time, so `get_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?

Viewing 1 replies (of 1 total)

 *  Thread Starter [mslade](https://wordpress.org/support/users/mslade/)
 * (@mslade)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ambiguous-get_queried_object/#post-6504739)
 * On further review it looks like `WP_Query`‘s internal `$queried_object` can be
   set in two places:
    - During `parse_query()` if a pagename is provided; that page is used.
    - In `get_queried_object()`:
 *  - if a category, tag, or custom taxonomy term is provided, that term is used
    - else if this is an archive request, the archive post type is used.
    - else if this is the posts page, that posts page is used.
    - else if this is any single post, that post is used.
    - else if this is an author page, that author is used.
 * Based on that, and because a query can satisfy both `is_tax` and `is_post_type_archive`,
   it appears that `get_queried_object` cannot be reliably used to determine the
   post type of an archive page.

Viewing 1 replies (of 1 total)

The topic ‘Ambiguous get_queried_object()’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [mslade](https://wordpress.org/support/users/mslade/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/ambiguous-get_queried_object/#post-6504739)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
