I’ve been struggling with this identified core bug regarding the post_type_archive_title() function which also affects the wp_title().

With debug mode on, hereby the messages I’m getting:

PHP Notice: Undefined property: stdClass::$labels in /wp-includes/general-template.php on line 700
PHP Notice: Trying to get property of non-object in /wp-includes/general-template.php on line 700

I’m trying to load the custom post type archive page but filtering the results by a specific taxonomy term. When doing this, post_type_archive_title function spits out an error because the “queried object” isn’t anymore the post type (e.g. Event) but the taxonomy (e.g. Venue). As an example of url which causes problems:

example.com/events/?venue=lisbon

A quick workaround


As suggested here the idea would be to workaround this issue by telling WordPress to ignore one of the conditionals is_tax or is_post_type_archive, both true in the example above. As suggested you could use the parse_query action hook, or in my version, using the pre_get_posts hook. Both hooks will work since they are altering the main query before the query is performed and before loading the template (where the wp_title and the post_type_archive_title will kick in).

add_action( 'pre_get_posts', 'my_pre_get_posts' );
function my_pre_get_posts( $query ) {

 if( is_admin() || !$query->is_main_query() ) {
  return;
 }

 if( $query->is_post_type_archive ) {
 //to solve issue http://core.trac.wordpress.org/ticket/18614
  $query->is_tax = '';
 }

}

Hopefully this bug will disappear on WordPress 3.7…