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.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 15:00 8:00 – 15:00 8:00 – 15:00 8:00 – 15:00 8:00 – 15:00 -
- 16:00 – 17:00 16:00 – 17:00 16:00 – 17:00 16:00 – 17:00 16:00 – 17:00 -

Supporter timezone: Europe/Rome (GMT+02:00)

Tagged: 

This topic contains 15 replies, has 3 voices.

Last updated by Alejandro 6 months, 3 weeks ago.

Assisted by: Alejandro.

Author Posts
January 6, 2022 at 2:09 pm #10299025

denysT-2

WPML SEO plugin allows you to set one of the categories as primary. However, if you translate your news, this feature does not synchronize in the secondary language.
Your code:

/**
	 * Translates the primary category ID.
	 *
	 * @param string $value
	 * @param int    $postId
	 * @param string $key
	 * @param bool   $single
	 *
	 * @return Indexable
	 */
	public function translate( $value, $postId, $key, $single ) {
		if ( '_yoast_wpseo_primary_category' === $key ) {
			$this->remove_hooks();
			$value = get_post_meta( $postId, $key, true );
			$this->add_hooks();

			$args     = [
				'element_id'   => $postId,
				'element_type' => get_post_type( $postId ),
			];
			$language = apply_filters( 'wpml_element_language_code', false, $args );
			$value    = apply_filters( 'wpml_object_id', $value, 'category', true, $language );

			if ( ! $single ) {
				$value = [ $value ];
			}
		}

		return $value;
	}

But we can see, that

$postId

from current post in admin panel, but we need get opposite post id (from post in default language) if post_meta

_yoast_wpseo_primary_category

in current $postId does not exist, otherwise this code has not working.

I also suggest that this code work in the translated language when the

$postId

is still unknown, but there is already a trid.

January 6, 2022 at 2:53 pm #10299933

denysT-2

Upd.
If post in different language and this a replicate from primary language (exactly primary) function working nearly correct (used id from the main category and not translated) . But if it's translation news, we have a bug.
Bug reproduced with featured image too, if post not have id, but i think it's a different ticket.

Why you not use post_id in translation post at once? It would help to avoid bugs.

January 8, 2022 at 11:23 am #10310123

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

I unfortunately don't fully understand the problem.

postID should be translated automatically according to the page, so it should always return a translated version of the post ID (and i bet that if you look around postID references a localized version post_id, somewhere).

However, you mention the following which is what's confusing me:

This a replicate from primary language (exactly primary) function working nearly correct (used id from the main category and not translated) . But if it's translation news, we have a bug.

do you mean DUPLICATE of a DEFAULT language?

I'm saying this because "Duplicate" and "translation" are 2 different things but also "Default Language" and "primary language".

A page can be created in whatever language you want, and that language will become the "original" or "default" language of the page but the default language of the site is the one that you set in WPML > Languages as the "main" language of the website.

----------------------------

Having said this, would you be able to replicate this issue here? --> hidden link

If you can indeed replicate the problem, i kindly ask you to write the steps that helped you do it, so i can follow them and run some tests to try to figure out what's going on.

January 10, 2022 at 8:05 am #10315763

denysT-2

Hi, this is very strange, here I can not reproduce the problem, I will look for an error in myself, perhaps a cache.

January 10, 2022 at 8:06 am #10315775

denysT-2

The problem is not fully resolved.

January 10, 2022 at 8:19 am #10315809

denysT-2

So I reproduced this.
Steps:
1. Create new post on ukranian lang (select "test category ua" and "test child category ua"), set the primary category "test child category ua"
2. Create translate on another languages (engilsh, spanish)
We can see selected 2 needed categories (checkboxes) on another language, but primary category (select) "test category", expected to see "test child category"

photo_2022-01-10_10-18-41.jpg
January 10, 2022 at 10:17 am #10317331

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Ok let's see because i don't think i understand very well, what the problem you're mentioning is.

this is what i found and what i tested: hidden link

as you can see:

- You hadn't translated anything, you created 2 different posts on 2 different languages, this means they are independent from each other.

- When translated, the content was always in sync, which is what was expected.

- You can't have different primary categories in different languages if they are translated from another language, they must always be the same one across all the languages.

Can you check everything out and let me know if i missed something? so far, everything seems to be in order, even when following your steps.

January 10, 2022 at 11:31 am #10317933

denysT-2

I not use WPML's Translation Editor.
See video screen
hidden link

I'm create post on Ukrainian language, after this, I click in translate this post to English language and I see added categories, but primary category (test child category en, for current post) is not selected. If I select primary category manually and saved post in English then it will be saved with category the one I chose, but it doesen't matter because I need a pre-filled category.

January 10, 2022 at 2:20 pm #10319619

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Please check this video: hidden link

what you are experiencing is normal, you can't see the "right" content because WordPress modifies this content through AJAX but WPML passes the info through the PHP hooks WordPress give us (there aren't AJAX hooks that could allow us to do this at the moment), so you can only see the change after you save the content and refresh the page.

at the same time if you DO make a change, and that change is different from the original one, it "might" stay selected and appeared as you modify it until the original language is updated. as soon as it is, the changes you made manually would be overwritten with the sync from the original language.

things like categories and the main category, will always be in sync with the original language.

Regards.

January 11, 2022 at 7:46 am #10324245

denysT-2

So, i produced step by step from your video and this is worked. But, we have nuaces:
1. As you can see, before save (translated VERSION) you opened new tab (1m 15s on your video) and this tab set a new global cookie language

wp-wpml_current_admin_language_ + hash

from spanish (es code).
2. After save (translated VERSION) you can see that the categories disappear (the checkboxes themselves) (1m 34s on your video).

Based on this, if you try to work in one tab and will not switch to the tab with another (required) languages, nothing will work for you and the main category will not be installed.
You can try to reproduce this in one tab without switching between tabs.

January 11, 2022 at 8:21 am #10324403

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

It's not about switching tabs. As I mentioned in the video, the problem is just that you need to refresh this page so the changes can be seen.

This is because WordPress uses AJAX to save the page but there is no way to execute and show the changes through AJAX yet (WordPress doesn't allow us to set the content and show it right away)

You don't have to switch tabs, you just have to refresh the page and that's it, you'll see it synced.

I actually tested this without changing any tabs and everything gave the same result as when I switched tabs, because, again, it's about refreshing the page, not about switching tabs.

January 11, 2022 at 8:51 am #10324657

denysT-2

Check this video. Step by step
1. Created a new post, select categories and select primary category, save draft
2. Created translated post for post from above step, save draft, reload page
It's doesent worked

hidden link

January 11, 2022 at 9:45 am #10325133

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Thanks for the video. i reproduced the problem as well and sent it to the developers.

I'll update this ticket as soon as i have answers from them.

Regards.

October 2, 2023 at 12:54 pm #14498161

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

A solution to this problem is scheduled to be included in WPML SEO V2.2.0.

Regards.

October 3, 2023 at 9:51 am #14503055

luc

Alejandro, when you think V2.2.0 will be deployed, I run into an issue acutely with Yoast / WPML and Primary Categoie, I suspect a bug in one of the 2 plugins.