Skip Navigation

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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Long Nguyen 1 year, 8 months ago.

Assisted by: Long Nguyen.

Author Posts
September 12, 2023 at 3:05 pm #14384915

eytanB

I am trying to: show links in categories in the CPT blog

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

I expected to see:all links to lead to english tax

Instead, I got: At the bottom of this page there are links to other cateogries, some of them lead to different language like hidden link I already tried this Go to WPML > Support > Troubleshooting > Clean up and click to run next:

POST - > Synchronize posts taxonomies

This is the code that displays those categories

<section class="block block-categories alignfull">
<div class="container">
<?php if (!empty($title)): ?>
<h2><?php echo esc_html($title); ?></h2>
<?php endif; ?>
<div class="categories-wrap">
<?php

// Get the current language
$current_language = apply_filters('wpml_current_language', null);

$terms = get_terms(array(
'taxonomy' => $tax,
'hide_empty' => true,
'lang' => $current_language, // Filter by the current language
));

foreach ($terms as $term) {
$icon = get_field('category_icon', $term);
$term_link = sprintf(
'%3$s%4$s',
esc_url(get_term_link($term->term_id, $tax)),
esc_attr(sprintf(__('View all posts in %s', 'freightos'), $term->name)),
wp_get_attachment_image($icon),
esc_html($term->name)
);

echo '<div class="category">' . sprintf(esc_html__('%s', 'freightos'), $term_link) . '</div> ';
}
?>
</div>
</div>
</section>

Screenshot 2023-09-12 at 9.02.01.png
September 15, 2023 at 3:01 am #14400191

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Eytan,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

You are using a custom code to display categories on your site, I would like to inform you that helping you with custom code, is out of the scope of WPML. But I can suggest you can check some points:

- "lang" parameter: I don't see this parameter is supported by WordPress, I think this won't work properly. Refer to the WP documentation https://developer.wordpress.org/reference/functions/get_terms/
- In the terms loop, you can use the filter hook "wpml_object_id" to get the translation term ID and get other term info based on the term ID. For example:

// Get the current language
$current_language = apply_filters('wpml_current_language', null);
foreach ( $terms as $term ) {
	$term_id = apply_filters( 'wpml_object_id', $term->term_id, 'mp-resource-category', false, $current_language );
	// get other term info by ID
}

Refer to the documentation https://wpml.org/wpml-hook/wpml_object_id/

If you are not able to accomplish this, I would recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Look forward to your reply.
Thanks

September 18, 2023 at 6:19 pm #14414835

eytanB

Hi,

I tested what you wrot and still gets the wrong link URL,
Our code is a normal code to show links for Terms in WP,
I also get the correct URL's in local duplicate of the site so It has to do something with the DB and the way WPML is setup,

Here is my updated code
// Get the current language
$current_language = apply_filters('wpml_current_language', null);

$terms = get_terms(array(
'taxonomy' => $taxonomy_name,
'hide_empty' => true
));

foreach ($terms as $term) {
// Exclude the current term from the list
if ($term->term_id !== $current_term->term_id) {
$term_id = apply_filters( 'wpml_object_id', $term->term_id, 'mp-resource-category', false, $current_language );
$icon = get_field('category_icon', $term);
$term_link = sprintf(
'%3$s%4$s',
esc_url(get_term_link($term_id, $taxonomy_name)),
esc_attr(sprintf(__('View all posts in %s', 'freightos'), $term->name)),
wp_get_attachment_image($icon),
esc_html($term->name)
);

echo '<div class="category">' . sprintf(esc_html__('%s', 'freightos'), $term_link) . '</div> ';
}

Can you have a look and help us fix this please,
Thanks!

September 19, 2023 at 1:19 am #14415733

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Please replicate the issue on a sandbox site, I will try to investigate the issue there. With this link, you can login directly to the admin area hidden link

Note: please do not restore your site on the sandbox site.

Look forward to your reply.
Thanks

September 25, 2023 at 9:27 pm #14462345

eytanB

Not sure what you mean, but my issue is realted to my current setup with CPT and taxonomies, I can't create it on the site you gave me, I can duplicate my site to a staging and give you FTP access if you want but this sandbox will not help in this case, please help!

September 26, 2023 at 4:25 am #14462905

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. It would be better to have a testing site where the issue is replicated. Your next reply is set to private to share the info.

And let me know where I can find the code on your site.

❌ IMPORTANT: Please backup your database and website before proceeding ❌
You can use this plugin to create the backup: https://wordpress.org/plugins/duplicator/
✙ I would need your permission to de-activate and re-activate Plugins and the Theme to change configurations on the site if needed. This is also a reason the backup is critical.

Look forward to your reply.
Thanks

September 26, 2023 at 3:30 pm #14468211

eytanB

The was resolved, not sure how but its fine now