Catchable fatal error theme fix

Posted on January 5, 2012

If when upgrading you get an error similar to this when visiting a single event or location page:

Catchable fatal error: Object of class WP_Error could not be converted to string in…..

There’s a good chance this applies to you.

A few users have had this issue and in all instances this was a theme related issue with regards to not being ready for WordPress Custom Post Types that don’t have regular post categories (and at least on category).

You can verify this by adding this:

function my_em_posttype_fix(){

to your theme’s functions.php file, visit the event, verify it still doesn’t work, edit the event and give it any normal wp cateogry, then view the event again. It hopefully works now.

A few alternatives to fix this for all events

You can either add regular post categories to events and locations, or fix your theme. Here’s two ways to assign post categories to get this working:

  • Do the above and bulk edit your events and locations, giving them the relevant category. Future events and locations should have a default category assigned.
  • Use the below snippet below the above snippet, and on visiting an event or location, it will assign ‘uncategorized’ if no categories exist. If you don’t have ‘uncategorized’, rename it to a category slug that does exist. You may need to reload the event page once, but from then on it’ll be ok for all visitors.
function my_em_posttype_cat_default($EM_Object){
	global $post;
	if( $post->post_type == EM_POST_TYPE_EVENT || $post->post_type == EM_POST_TYPE_LOCATION ){
		$categories = get_the_category();
		if( count($categories) == 0 ){
			//assign a category to this
			wp_set_object_terms($post->ID, 'uncategorized','category');
add_action('template_redirect','my_em_posttype_cat_default', 1,1);

One Comment

  1. […] Fixing a theme-caused catchable error warning […]