Undefined property: stdClass::$labels in general-template.php post_type_archive_title()

This is a bug (one that I’ve encountered before) and could do with a ticket in trac (since I never took the time to submit one!)

The trouble starts with requests that set multiple is_* query flags as true (specifically flags that represent objects, such as single posts, pages, and post type & term archives).

This is because there can only ever be one “queried object” (in your case it’s the term).

Now the reason wp_title() seems to throw a wobbly is down to another function it calls:

function post_type_archive_title( $prefix = '', $display = true ) {
    if ( ! is_post_type_archive() )
        return;

    $post_type_obj = get_queried_object();
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );

    if ( $display )
        echo $prefix . $title;
    else
        return $title;
}

Since the is_post_type_archive flag is true, it assumes the queried object is a post type, and tries to access an undefined property of what is actually a term object.

Whether the fix is to open up the possibility of multiple queried objects, or to implement more rigourous checking of them, I’m not sure, but I’ll get it on trac & we’ll see what follows.

Update: To suppress the error (& possible others), “switch off” one of the flags:

add_action( 'parse_query', 'wpse_71157_parse_query' );
function wpse_71157_parse_query( $wp_query )
{
    if ( $wp_query->is_post_type_archive && $wp_query->is_tax )
        $wp_query->is_post_type_archive = false;
}

Leave a Comment