Categories:> WordPress

The Events Calendar – Tags – Posts Not Found

I recently ran into a problem with a client’s website, where click-throughs from the WordPress tag cloud, and the get_tags() function were displaying a ‘Posts not found’ error message. After some digging, I realised that this only applied to tags associated with posts, tags associated my custom posts were returning results as expected.

After much googling, I eventually found out I was not alone, and the bug had been traced back to the WordPress Events Calendar plugin. Luckily Barry Hughes, the plugin author had already posted a solution. Just add the following lines to your functions.php file:

add_action( 'parse_query', 'tribe_fix_tag_query' );
function tribe_fix_tag_query( $query ) {
	if ( $query->is_tag && (array) $query->get( 'post_type' ) != array( TribeEvents::POSTTYPE ) ) {
		if ( empty( $query->query_vars['post_type'] ) ) {
			$query->query_vars['post_type'] = array( 'post' );
		}
		if ( ! ( $query->query_vars['post_type'] == array( 'post' ) || $query->query_vars == 'post' ) ) {
			remove_action( 'parse_query', array( 'TribeEventsQuery', 'parse_query' ), 50 );
			remove_action( 'pre_get_posts', array( 'TribeEventsQuery', 'pre_get_posts' ), 50 );
		}
	}
}

Hope that helps someone!

Share

About Ross Gledhill See all posts by author

I’m Ross, a freelance web developer based in Glasgow, Scotland. The large majority of my freelance work usually involves WordPress, but I also have experience in iPhone & iPad apps and bespoke solutions.