Please make sure to update to WPML 4.3.4 before reporting any issue

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.

This topic contains 7 replies, has 2 voices.

Last updated by Makarand Mane 6 months, 3 weeks ago.

Assigned support staff: Bruno.

Author Posts
April 19, 2019 at 1:07 pm #3645883

Makarand Mane

I am trying to: I have disabled translation for course post type & course category are translatable.
Link course in translated category - I will publish course & it should be shown on translated category.

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

I expected to see:When I publish course it should count under category in another language.

Instead, I got:Category in other language are empty.

When course is published or saved, how I can insert same course in category present in other language . I need to code to find category alternate category and insert term to course.

April 20, 2019 at 12:27 am #3648551

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. From what I understand, you are wanting to display the content in the default language, but the categories you want to display the translated ones, is that correct?

If so, you will need custom coding. This is because WPML will associate the translated category with the content of that category. Since the category has no content associated with it, then they are not displayed.

Please note that custom coding is beyond the scope of our support.

We have a list of WPML and WooCommerce Multilingual hooks that can help you develop such feature, which can be seen in the links below:

- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/

If you prefer, you can contact one of our certified partners who can develop small to large features for your site: http://wpml.org/documentation/support/wpml-contractors/

Thank you.

April 20, 2019 at 4:44 am #3649513

Makarand Mane

I know it is custom work, but I am not asking you to write code for me. I am asking you hint.

As I know I have to hook code on save_post. There I need to check to alternate category in another language. One I get term ID, I can add terms.

Let me know how to get category term ID in alternate language

April 23, 2019 at 4:09 am #3659587

Makarand Mane

Are you interested to help?

April 23, 2019 at 2:15 pm #3664567

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Yes of course. I'm here to help. I have already indicated a list with our available hooks that you can use.

You can check the wpml_object_id, which will convert the ID of a taxonomy (or page, post, custom post) between the translated ID: https://wpml.org/wpml-hook/wpml_object_id/

The hook save_post should not be useful because you will not be saving secondary language content so this should not be useful.

You may need to simply filter the categories on the front end. WordPress itself has filters that you can test, such as get_the_categories: https://developer.wordpress.org/reference/hooks/get_the_categories/

Maybe your own theme has some hook that can help you in this, but I'm not aware. The suggestion should basically be to filter the category on the front end.

I hope these tips are useful.

Thank you.

April 30, 2019 at 4:41 am #3707859

Makarand Mane

Here is code I prepared to attach translated categories to same post.

 add_action( 'wp_insert_post', 'learny_course_duplicate_on_publish' );		
function learny_course_duplicate_on_publish( $post_id ) {
	global $post;
	
	// don't save for autosave
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
		return $post_id;
	}
	// dont save for revisions
	if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
		return $post_id;
	}
	
	if ( $post->post_type != 'course' ) {
		return $post_id;
	}
	
	//Things fail at AJAX, front end submission
	global $sitepress, $wpml_term_translations;

	$term_utils = new WPML_Terms_Translations();
	$wpml_term_translations->reload (); 
	
	$language_details_original = $sitepress->get_element_language_details( $post_id, 'post_' . $post->post_type );

	if ( $language_details_original ) 
		return;
	
	$langs = $sitepress->get_active_languages() ;
	
	$taxonomies = get_post_taxonomies($post_id);

	foreach ( $taxonomies as $tax ) {
		$terms = wp_get_object_terms ( $post_id, $tax );
		$translated_terms =array();
	
		/** @var int[] $translated_terms translated term_ids */
		wp_delete_object_term_relationships( $post_id, $tax );
		foreach ( $langs as $lang => $details ) {
			if ( $lang != 'en' ) {			
				foreach ( $terms as $term ) {
					$translated_terms[ ] = $term->term_id;
					$translated_id = (int) $wpml_term_translations->term_id_in ( $term->term_id, $lang );
					if ( $translated_id ) {
						$translated_terms[ ] = $translated_id;
					}
				}
			}
		}
		wp_set_object_terms ( $post_id, $translated_terms, $tax );
		
	}
	clean_object_term_cache ( $post_id, get_post_type ( $post_id ) );
	
}
April 30, 2019 at 8:27 pm #3714837

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for sharing the code you are using. From what I understand from the code, you're taking the translated categories and adding them to the original content category list, correct? Is this code that you posted working as expected?

Thank you.

May 1, 2019 at 5:05 am #3716003

Makarand Mane

From what I understand from the code, you're taking the translated categories and adding them to the original content category list, correct? YES, that is what I was asking from beginning.
Is this code that you posted working as expected? YES

I resolved my issue myself. Thank you!