If you are having a notice about writing the .mo files please read this doc

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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 6 replies, has 2 voices.

Last updated by Julien 1 year ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
October 19, 2018 at 8:27 pm #2833031

Julien

Hi
I'm trying to display all the categories in both languges thanks to the function get_terms()
but only french categories are display not the english one: here is my code

$product_categories = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
) );
echo"<h1>Catégories</h1>";

echo "<table style='border:1px solid'>";
echo "<tr><td> Permalink</td> <td>ID</td> <td>Title</td><td>Langue</td></tr>";

if( !empty($product_categories) ){

foreach ($product_categories as $key => $category) {
$get_correct_ID_lang = icl_object_id($category, 'category', TRUE,ICL_LANGUAGE_CODE);

// foreach ($all_languages as $lang => $row) {
// if ($term_id = icl_object_id( $category->term_id, 'product-category', false, $lang )){
// echo "<tr><td>\n\n".get_term_link($category)." </td><td>\t".$category->term_id."</td>\t<td>\t".$category->name."</td><td></td></tr>";
// }
$all_languages = icl_get_languages();
// echo $all_languages["fr"]['language_code'];
// echo $all_languages["fr"]['language_code'];
// echo "<br>";
// echo "<br>";
// echo "<br>";
// var_dump( $all_languages);

echo "<tr><td>\n\n".get_term_link($category)." </td><td>\t".$category->term_id."</td>\t<td>\t".$category->name."</td><td>".$all_languages['default_locale']."</td></tr>";

}

}
echo "</table>";

October 22, 2018 at 5:15 am #2836781

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Thank you for contacting WPML support. I'd be happy to assist you further on this issue.

WPML filters the results of the get_terms according to the languages as a reason you can see the results only in the selected languages.

Since the request is related to creating custom functions, I would request you to use our API instead, https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

You can use the following hook, https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-662213, which normally switches the languages, so now switch the language one by one and get the terms then combine all the terms into one array to make this work.

Kind Regards,
Shekhar

October 22, 2018 at 6:39 pm #2839468

Julien

hi

sorry didn't really get the answer;
Want I need is to able to display for a category:
- the permalink
-the Id
-the langague
-the title

I use this code to do the same for pages, so I wonder what would be the equivalent for the categories

echo"<h1>Pages</h1>";
$page_ids=get_all_page_ids();
echo "<table style='border:1px solid'>";
echo "<tr><td> Permalink</td> <td>ID</td> <td>Title</td><td>Langue</td></tr>";
foreach($page_ids as $page)
// foreach($post as $post)
{

$my_post_language_details = apply_filters( 'wpml_post_language_details', NULL, $page ) ;

echo "<tr><td>\n\n".get_page_link($page)." </td><td>\t".$page."</td>\t<td>\t".get_the_title($page)."</td><td>".$my_post_language_details['locale']."</td></tr>";

}

thank a lot

October 23, 2018 at 9:06 am #2841621

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

I am sorry but providing custom code solutions doesn't fall under the support policy, so, at this point, I would suggest you consider contacting one of our certified partners from this link:
http://wpml.org/documentation/support/wpml-contractors/

Before doing so please have a look also here:
http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/

You will get the custom assistance you need to get on with your project.

Thanks

October 23, 2018 at 4:51 pm #2843612

Julien

ok sorry for the code, I thought it would be easier to understand the issue.
So the thing is while using the get_terms function I am not able to get access to the categories translated at the same time as the current language category.

October 24, 2018 at 3:57 am #2844821

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

While using get_terms() function it automatically filters the content according to its languages, so if you are viewing the results in the French language it will display the French results and if in English it will display in English accordingly.

The following code works perfectly to retrieve the results.

$product_categories = get_terms( array(
'taxonomy' => 'category',
'hide_empty' => false,
) );

Let me know if this helps.

Thanks

October 25, 2018 at 12:55 am #2848095

Julien

My issue is resolved now. Thank you!