Skip to content

Instantly share code, notes, and snippets.

@ny0m
Last active December 18, 2015 00:38
Show Gist options
  • Save ny0m/5697529 to your computer and use it in GitHub Desktop.
Save ny0m/5697529 to your computer and use it in GitHub Desktop.
PHP function to fix Wordpress error "Undefined property: stdClass::$labels in general-template.php (for this Trac ticket: http://core.trac.wordpress.org/ticket/20994). I needed it to fix the title send in an RSS feed for my custom taxonomy, but helps with quite a few edge cases. Just paste into functions.php
<?php
add_action('pre_get_posts', 'fix_title');
function fix_title(){
global $wp_query;
if ( $wp_query->is_post_type_archive && $wp_query->is_tax ) {
global $queried_object;
$queried_object = get_queried_object();
$queried_object->labels = new stdClass();
$queried_object->labels->name = $queried_object->name;
return $queried_object;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment