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 11 replies, has 3 voices.

Last updated by jakubK-15 1 year, 1 month ago.

Assigned support staff: Itamar.

Author Posts
August 14, 2018 at 7:51 am #2642546

danielm-86

I am trying to: Have custom post rule with translated slug working

I expected to see: The page with the content

Instead, I got: A 404

Before giving me advices, please take into account that I :

* Save permalinks, no effect
* Custom post slug is translated. Works in original language, not in translated

August 14, 2018 at 8:49 pm #2644638

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I think that your case matches a known issue that we have.
Please see the following errata page and try the suggested workaround and tell me if it is working in your case.
https://wpml.org/errata/wpml-redirection-and-issues-with-custom-rewrite-rules/

Best Regards,
Itamar.

August 15, 2018 at 5:12 am #2645598

danielm-86

Hi!

Not, it doesn't do anything. Also, we have other sites with the same kind of configuration, and they works. What could be the other causes of this problem?

Best,

August 15, 2018 at 10:58 pm #2647949

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

Can you please elaborate how do you set this custom post rule/configuration?
Please elaborate as much as you can on this issue and add code snippet if it involves custom code. Also, sometimes screen-shots illustrating what you mean may go a long way to clarify what words fail to transmit, so if you like, make use of “upload an image” below the comment area.

Thanks,
Itamar.

August 17, 2018 at 5:16 am #2652200

danielm-86

Hi!

Here's the code that creates the Custom Post:

$args = array(
		 	'labels' => array(
		 		'name' 				=> __('Regroupements', 'tp1-project'), 
		 		'singular_name' 	=> __('Regroupement', 'tp1-project'), 
		 		'menu_name' 		=> __('Regroupements', 'tp1-project'), 
		 		'add_new_item' 		=> __('Ajouter un regroupement', 'tp1-project'),
		 		'edit_item'			=> __('Modifier un regroupement', 'tp1-project')
		 	),
			'menu_position' => 10,
			'capability_type' => 'post',
			'exclude_from_search' => false,
			'has_archive' => true,
			'hierarchical' => true,
			'public' => true,
			'rewrite' => array('slug' => get_option('tp1_base_grouping'), 'with_front' => false, 'feeds' => false),
			'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')
		);

You can see in the first image, that it's translated correctly. However, using the plugin Rewrite Rules Inspector, rewrite rules are missing for the slug in English. The results I see are in the second image. Basically, there is rewrite rules for the French slug, but not the English one. My problem is there. Flushing rules does nothing. Any ideas on what is the problem?

Thanks.

August 20, 2018 at 4:29 pm #2660205

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi and thank you for elaborating further on this issue.

There are a few things that I would like to point out.

1. The code that you have shared with me seems to be only part of the function register_post_type so I could not fully examine it.

2. The default language of your site is French. And you create the Custom Post Type in French. But in the following screenshot that you have shared with me for the translation of the slug in the Strings Translation section, you translate the slug from English to French where I expect you to translate it from French into English. hidden link

3. You have not shared with me the code that you have said that did not work for you. I mean the code that is suggested on our errata page at the following link. Maybe there is something wrong with the way that you have changed this code. https://wpml.org/errata/wpml-redirection-and-issues-with-custom-rewrite-rules/

I think that it would be best if we will try to replicate this issue on a clean WordPress installation. I created a test website with a clean WordPress install. You can access it through this link: hidden link - Through this link, you will be automatically logged in.

Could you please set up everything the same way that it is set up on your site and add to the default WordPress theme (Twentyseventeen) the custom code for creating the Custom Post Type?

You will only need to configure WPML with the languages the way that it is configured on your site. You do not need to add any of your plugin or the theme. We just want to see what goes wrong with the custom code that you add and what goes wrong with the rewrite rules.

Please let me know when it is done so I can check it.

Thanks,
Itamar.

August 20, 2018 at 5:24 pm #2660376

danielm-86

Hi!

It would be better if I can duplicate the website in its entirety. It is because we have files in mu-plugins and all over the place. Can you provide me with a form to send you the package?

Thanks.

August 20, 2018 at 10:32 pm #2661103

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

Please share with me the copy of your site.
You can upload it to a service like Google Drive or Dropbox and share the link with me.
For this I'll enable private message for the next reply.

Thanks,
Itamar.

August 22, 2018 at 11:00 am #2666520

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi and thank you for sharing your site with me.

I've installed it on my local server but to help you I need more information, please.

1. How can I see the problem on your site?
Please tell me where do I need to go to see that the rewrite rule is not working and I get a 404 page.

2. The code that you have shared with me seems to be only part of the function register_post_type so I could not fully examine it.
Where in your site's files, can I find the rewrite rule that you have added above?
I could not find it in the functions.php file of your theme.

I look forward to your reply, so I could continue debugging this issue.

Regards,
Itamar.

August 23, 2018 at 10:24 pm #2671702

danielm-86

Hi!

for your 1) use the links hidden link. This is the page that gives a 404

for your 2) see the file wp-content/mu-plugins/tp1-project/class-post-types.php. This is where the custom post are defined.

Meanwhile, I make some progress on my own. I modify the slug of the custom type to have a French one. I also modify the translation to have it revert to original in French. I had some problems with the old slug keeps reappearing in the Setting of WPML, but now everything seems to be working! (Please see the picture) Can you see on your side if this solve the problem?

Thanks!

August 26, 2018 at 1:14 pm #2676210

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

Yes, it is solving the issue on my side as well, and this is the correct way to do that.

Please confirm that this issue is solved now.

Best Regards,
Itamar.

October 30, 2018 at 1:32 pm #2862013

jakubK-15

I had the same problem.

Wordpress: 4.9.8
WPML: 4.0.8
WPML String Translation: 2.8.8

Site default language was set to Polish.
CPT's rewrite slugs were defined and registred in English.

// ...
'rewrite' => array(
	'slug' => 'product-slug'
)
// ...

Ofcourse slug translation for my CPTs didn't work.

So I experimented with settings in
"Set different slugs in different languages for [my CPT]."
(WPML -> Settings -> Post Types Translation)
That didn't help at all.

Then I started digging deeper in DB and I've found it !!!

When you set a language of originally registred slug (in Post Types Translation) WPML does not clean translation entry in wp_icl_string_translations table

In my case I had orignal English entry in wp_icl_strings table:

{[
    id: 6069,
    language: en,
    context: WordPress,
    name: URL slug: product,
    value: products-slug,
...
    status: 10,
...
}]

and two reffering translations, including English one (was different than the orignal), in wp_icl_string_translations table
table wp_icl_string_translations

[{
    id: 5678,
    string_id: 6069,
    language: pl,
    status: 10,
    value: produkty-slug,
    ...
}, {
    id: 5682,
    string_id: 6069,
    language: en,
    status: 10,
    value: products-en-slug,
    ...
}]

I manually removed English entry (id: 5682) from DB and slug translation for my CPT started to work.