Skip Navigation

[Resolved] Translated Custom Taxonomies show as "No items found" using non-default language

This support ticket is created 4 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 11 replies, has 2 voices.

Last updated by simonM-5 4 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1400211
Screenshot 2019-12-04 at 21.20.07.png
Screenshot 2019-12-04 at 21.19.08.png

Hi Support

Me again 🙂

I am trying to:
Perform a custom search using translated custom taxonomies.

Link to a page where the issue can be seen:
hidden link

Steps to reproduce in English:
1) Under "OTHER LANGUAGES" click "Turkish" and run the search - one Nanny is found correctly and all taxonomies display correctly.

Steps to reproduce in German (similarly not working in Spanish but for clarity just describing German here):
1) Under "ANDERE SPRACHEN" click "Türkisch" and run the search - the same one Nanny is found correctly, however all the Views built on custom taxonomies display the English phrase "No items found" (the classic phrase from the Loop Items when nothing is found)

I expected to see:
The same Nanny being found (she is), but with the term "Türkisch" appearing under "ANDERE SPRACHEN" on the right hand side in the search results.

Instead, I got:
"No items found"

We translated all our custom taxonomies centrally using WPML > Taxonomy Translation feature, and I believe we have done this correctly.

As the correct number of results is returning, I suspect that it is just some kind of display problem, or the tool is having some difficulty retrieving the translated results.

In any case, our requirement is that the language in which the records are created should be immaterial, the taxonomies should always translate, since all translations are available and I believe we have the WPML settings correctly set.

Thanks and regards
Simon

#1400415

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for contacting us and I'd be happy to assist.

I noticed that you're using two child views to show the text under "NATIVE LANGUAGES" and "OTHER LANGUAGES".

These attached taxonomy terms can be shown without these child views, through the "wpv-post-taxonomy" shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy


NATIVE LANGUAGES:
{!{wpv-post-taxonomy type="native-language" format="name"}!}


OTHER LANGUAGES:
{!{wpv-post-taxonomy type="other-language" format="name"}!}

You can add these shortcodes in the content template of your view "Find a Native Nanny Search and Results View" and they should show the terms correctly.

I hope this helps and please let me know how it goes.

regards,
Waqar

#1400761

HI Wagar

The reason I didn't use the shortcode is that I cannot sort the items in a preferred order (as far as I know?). When we have the terms displayed from a View, we can sort by the internal slug which we can order how we like or rather in a sensible order, otherwise eg AVAILABLE DAYS sorts alphabetically instead of Monday - Sunday and TIME OF DAY sorts alphabetically instead of chronologically etc.

Cheers
Simon

#1401433

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for sharing further details.

The "wpv-post-taxonomy" shortcode can only show terms ordered by the name, so you're correct that you'll have to use child views to have more control over the ordering of the terms.

During tests on my own website with similar child taxonomy views, I couldn't reproduce this issue and results showed as expected.

To troubleshoot why this isn't working on your website, its clone/snapshot will be needed. Can you please share it as explained in this guide?
https://toolset.com/faq/provide-supporters-copy-site/

Note: Your next reply will be private.

regards,
Waqar

#1401521
#1402677

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for sharing the duplicator package and I've managed to successfully deploy it on my own server.

I'll be performing some tests on this and will update you with my findings, as soon as it completes.

regards,
Waqar

#1405175

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for waiting.

During testing on your website's clone, I noticed that for this specific requirement of showing the attached terms in a custom order, you'll need a custom shortcode which will offer more flexibility.


add_shortcode( 'get_terms_custom_order', 'get_terms_custom_order_func');
function get_terms_custom_order_func($atts) {
	$a = shortcode_atts( array(
		'id' => '',
		'type' => '',
		'orderby' => '',
		'order' => '',
		'sep' => ''
	), $atts );

	$terms = wp_get_post_terms( $a['id'], $a['type'], array('orderby' => $a['orderby'], 'order' => $a['order']) );

	$sep = $a['sep'];

	$output = '';
	
	foreach ( $terms as $term ) {
		$output .= $term->name;
		$output .= $sep; 
	}
	
	return rtrim($output, $a['sep']);
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

After that you'll be able to use this shortcode in your view, like this:


NATIVE LANGUAGES:
[get_terms_custom_order id="{!{wpv-post-id}!}" type="native-language" orderby="slug" order="DESC" sep=", "]
 
 
OTHER LANGUAGES:
[get_terms_custom_order id="{!{wpv-post-id}!}" type="other-language" orderby="slug" order="DESC" sep=", "]

Feel free to adjust the attribute values of this shortcode as needed and for reference of possible "orderby" attributes, you can visit:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters

I hope this helps and let me know how it goes.

regards,
Waqar

#1405449

Hi Wagar

Thanks for the custom code. I activated it under Toolset > Settings > Custom code. Unfortunately we are not seeing any difference in German. We are still seeing "No items found".

I tried two variants:

Your original suggestion with sort order changed from DESC to ASC:

[get_terms_custom_order id="{!{wpv-post-id}!}" type="native-language" orderby="slug" order="ASC" sep=", "]

and the same again using square brackets:
[get_terms_custom_order id="[wpv-post-id]" type="native-language" orderby="slug" order="ASC" sep=", "]

1) What is "type" expecting? A View slug? A Taxonomy slug?
2) In what format would you expect your custom code to return the results?
a) in one comma separated line (eg in German) "Englisch, Deutsch, Spanisch, Türkish" or
b) in a list, eg

Englisch
Deutsch
Spanisch
Türkish

Our requirement is simply to see the German versions in the list form, as in the EN version of the website.

Thanks and regards
Simon

#1405645

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

I noticed that you've placed this shortcode in the existing taxonomy view "Native Languages View", which is not correct.

It should be added in the content template "Loop item in Find a Native Nanny Search and Results View":
hidden link
( in place of that view's shortcode: hidden link )

Also please remember to update the shortcode in all translated versions of this content template.
( screenshot: hidden link )

It seems that the shortcode's code has been removed from the "Custom code" section, so please add it back before checking.

1) What is "type" expecting? A View slug? A Taxonomy slug?
- As shown in the example shortcodes, type attribute expects slug of the required taxonomy.

2) In what format would you expect your custom code to return the results?
- The shortcode is designed to return the names of the terms, separated by what you'll specify in the "sep" attribute.

For a comma-separated list, you can use ", " as in the example shortcodes and for each item on a new line, you can use "<br>" tag.
hidden link

regards,
Waqar

#1405873

HI Wagar

Thanks a lot for that. I have made the changes and we are seeing a huge step forward now.

All values are being retrieved correctly in English and German and are sorting according to the slug as specified.

However I'm struggling to get each item on a line of its own using the <br> tag, because it keeps misinterpreting it as a line break as soon as I save the Content Template.

Is there a supported way to force the HTML to use the <br> tag or perhaps another method to get a new line, eg \n or the likes?
I thought of perhaps using the ordered list <ol> to produce the list also, but I'd prefer not to have any symbol before each entry in the list if possible.

Thanks and regards
Simon

#1406397

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thanks for the update and glad that the shortcode is working.

It seems that the Fusion Builder is stripping the br tag. To avoid this, you can follow these steps:

1. In the code snippet that I sent earlier, you can update the line# 9, to include the br tag, by default:


'sep' => '<br>'

2. After that, you can remove the "sep" attribute from your shortcodes and it will be used automatically:


NATIVE LANGUAGES:
[get_terms_custom_order id="{!{wpv-post-id}!}" type="native-language" orderby="slug" order="DESC"]
  
  
OTHER LANGUAGES:
[get_terms_custom_order id="{!{wpv-post-id}!}" type="other-language" orderby="slug" order="DESC"]

I hope this helps.

#1408629

My issue is resolved now. Thank you! Another top job Toolset! 😀

#1411287

Hi Wagar/Support

Regarding our recently resolved ticket "[Resolved] Translated Custom Taxonomies show as "No items found" using non-default language".

We have noticed that the German and Spanish translations are sorting by the English name, eg the list

English
German
Spanish

from the taxonomy "other language" is returning in German as

Englisch
Deutsch
Spanisch

Would it be possible to have the taxonomies which are ordered by "name" to return alphabetically in the translated language? ie

Deutsch
Englisch
Spanisch

In other words that the translated names get sorted alphabetically instead of the original English names, eg by adding a language parameter to the custom code or similar?

Kind regards
Simon

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