Skip Navigation

[Resolved] Taxonomy filter not working when view is inserted on pages translated with WPML

This support ticket is created 8 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Tagged: 

This topic contains 1 reply, has 1 voice.

Last updated by Jakob 8 years, 4 months ago.

Author
Posts
#353681

I have a view listing all the items in a particular post type. The site has WPML installed.

When I include the view on a page in the default language, the view works fine, including a taxonomy query filter based on URL parameters.

When I include the view on a page translated into the second language, the view works fine without the URL parameters/taxonomy filter, but not with the filter.

In WPMLs "Language URL format" setting, I have chosen "Different languages in directories" (not checked "Use directory for default language ").

I have searched the forums for solutions. The closest thread, I've found is these ones:

https://toolset.com/forums/topic/views-filter-not-working-in-secondary-language/

https://toolset.com/forums/topic/views-filter-still-not-working-in-secondary-language/

But I don't see a solution there.

#353741

I turned on the Views debug tool (very useful) and found out that, in this situation, Views is sending the taxonomy terms in the German versions. German is the secondary language, with English being the default language.

Then I found out that I could do a workaround by using wpv_filter_query, like this:

if ( isset( $_GET['wpvprofession'] ) ) {

	add_filter( 'wpv_filter_query', 'jakob_filter_allcourses', 20, 1 );

	function jakob_filter_allcourses( $query_args ) {
	    
	if ( $query_args[tax_query][0][terms][0] == 31 ) { 
	$query_args[tax_query][0][terms][0] = 3;
	} else if ( $query_args[tax_query][0][terms][0] == 32 ) { 
	$query_args[tax_query][0][terms][0] = 4;
	} else if ( $query_args[tax_query][0][terms][0] == 33 ) { 
	$query_args[tax_query][0][terms][0] = 5;
	} else if ( $query_args[tax_query][0][terms][0] == 34 ) { 
	$query_args[tax_query][0][terms][0] = 14;
	}

	if ( $query_args[tax_query][1][terms][0] == 26 ) { 
	$query_args[tax_query][1][terms][0] = 6;
	} else if ( $query_args[tax_query][1][terms][0] == 27 ) { 
	$query_args[tax_query][1][terms][0] = 7;
	}

	if ( $query_args[tax_query][2][terms][0] == 28 ) { 
	$query_args[tax_query][2][terms][0] = 9;
	} else if ( $query_args[tax_query][2][terms][0] == 29 ) { 
	$query_args[tax_query][2][terms][0] = 11;
	} else if ( $query_args[tax_query][2][terms][0] == 30 ) { 
	$query_args[tax_query][2][terms][0] = 10;
	}

	return $query_args;

	}

}

Basically I am exchanging the German term ids with the English ones and the end result is working for me. If you see any weaknesses in this approach, I welcome your feedback.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.