This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using PHP to pull the slug for a custom post type, but the slug is not showing correctly and the link is breaking.

Solution: You will need to adjust your code to use the urldecode, because by default browsers want urls encoded. One of our developers shared this link which should help point you in the right direction: https://www.php.net/manual/en/function.urldecode.php

Relevant Documentation: https://www.php.net/manual/en/function.urldecode.php

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Mateo 2 weeks ago.

Assigned support staff: Lauren.

Author Posts
October 3, 2019 at 3:20 pm #4689391

Mateo

I am trying to:

Pull the translated terms for a custom taxonomy. The $term->name is correctly encoded and uses the chinese characters, but the $term->slug looks like this %e5%8f%a3%e8%aa%aa

Link to a page where the issue can be seen:

hidden link

I need these term slugs to be in the correct chinese characters. In settings under "the edit languages" for chinese I have changed "encode URLS" to Yes. But this didn't fix it.

Any help appreciated

Thanks

October 3, 2019 at 3:42 pm #4689499

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thank you for contacting WPML support. I'll be happy to help you with this.

I checked the link you shared in your original post and the translated URL seems to be working correctly for me. It takes me to the encoded URL (please see attached screenshot).

Perhaps you can send me a screenshot of where you see it not working so that I can better understand the issue?

October 3, 2019 at 4:32 pm #4689817

Mateo

Hi Lauren,

You're right the URL is translated, but that's not the real issue - the issue is that the slugs for my custom taxonomy terms are stored unencoded.

The $term->name is correctly encoded and uses the chinese characters, but the $term->slug looks like this %e5%8f%a3%e8%aa%aa

How can I make sure the taxonomy terms remain in chinese characters?

ON the taxonomy translation screen I've entered the slug using chinese characters, but it would appear that they're being stored an unencoded.

For example I run some php to pull the name of the term and slug, and the output is this

<button type="button" data-toggle=".%e7%be%8e%e8%a1%93">美術</button>

You can see the $term->name in chinese and the $term->slug (the value of the data toggle) is unencoded. Since this unencoded term contains "%" characters it doesn't work as a CSS class value, and hence my code is broken.

October 3, 2019 at 5:03 pm #4689943

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thanks for clarifying. It looks like you will need to adjust your code to use the urldecode, because by default browsers want urls encoded. One of our developers shared this link which should help point you in the right direction: hidden link

Due to our support policy I"m not able to provide custom work as a solution, but hopefully this documentation will help you find a resolution.

October 4, 2019 at 5:13 am #4692765

Mateo

Great. I used the urldecode function on the encoded slug. All good now.