null on post date archives (page type
is_date()) and the main blog index page (page type
is_home()). Is this intentional, or just an oversight?
I was writing a wrapper around get_queried_object() to get the title of the current page, no matter what type of page it is, for use in a theme. I quickly realized that instead of using
get_query_object() I should just duplicate the important bits from
wp_title(), but before that I came across an interesting issue.
It appears that
get_queried_object() and its root function
null for a couple of listing types, including the primary posts list output by index.php (page type
is_home()) and post archives by date (page type
I tested this by throwing the following snippet into a number of template files in a number of locations, always after
get_header() and before
<pre><code><?php $queried_object = get_queried_object(); var_dump( $queried_object ); ?></code></pre>
This works perfectly on category archives, tag archives, custom taxonomy archives, and custom post type archives.
get_queried_object() returns the query object, which can be used to extract a page title and other useful information.
However, it fails in archive.php for standard post date archives and index.php for the normal blog posts home page list view.
Digging into the source of
WP_Query->get_queried_object() reveals something rather unsurprising: there is no check for page type
is_home() or page type
is_date(), so on those page types
$this->queried_object = null; is not updated and the function returns
So my question is, is this intended functionality (e.g. are you not supposed to use get_queried_object() on those pages), a technical limitation (is there not a meaningful object to return on those pages), or simply an implementation oversight?
Is there even an equivalent of the custom post type object for the built-in "blog post" post type to display?