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

Last updated by Itamar 1 month, 3 weeks ago.

Assigned support staff: Itamar.

Author Posts
August 19, 2019 at 12:25 pm #4415925

Willem

We sometimes get a 404 on a custom posttype, and i'm aware it can be resolved by saving the 'Permalink Settings'. However, i don't want my client to press this button every time he/she modifies some content and i don't want to add a flush_rewrite_rules() to each individual request, since that have a severe impact on page-speed.

I'm not sure what causes the problem, but i don't think it is the correct way to have to save the permalink settings each time you modify some content.

So my questions are:
1) is this expected behavior?
2) Whats the preferred way to flush the rewrite rules (without adding flush_rewrite_rules() on init)

August 19, 2019 at 6:28 pm #4418297

Itamar
Supporter

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

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

Hi.

This is not expected behavior, and if everything is correct and updated, it shouldn't happen.
You wrote: "We sometimes get a 404 on a custom posttype..."
Do you know under which conditions you get the 404?
Is everything (WordPress, WPML and its add-ons, replate theme and plugins) updated on your site?
Could you please share your Debug information with me?
You can read the detailed explanation about it here.
http://wpml.org/faq/provide-debug-information-faster-support
The debug info will give me a lot of information about how your site is configured and will help me understand the source of the problem.

Regards,
Itamar.

August 20, 2019 at 7:49 am #4421119

Willem

I'm not a 100% sure when this occurs, but i do know it happened after new content was added or modified in another language. If i had to guess, it seems the permalinks are only saved for the language the editor was working in, and the other languages will give 404-errors.

August 20, 2019 at 12:32 pm #4423657

Itamar
Supporter

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

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

Hi and thanks for sharing the debug information with me.

I can see that you are on a WordPress multisite installation. Therefore I cannot see the plugins that you use and whether everything is updated.
Can you please confirm that WPML and its add-ons, and any related plugins or the theme are updated to the latest versions?
By related plugins, I mean the plugins that create the Custom Post Type.
If not then please update everything and see if the issue persists.

Also please share with me the link to where I can see this issue (404 on translated CPT).

You wrote: " If i had to guess, it seems the permalinks are only saved for the language the editor was working in, and the other languages will give 404-errors."
It sounds to me that you are not translating the CPT posts correctly.
Can you please further elaborate on the CPT that you using?
Is it created by your theme, a plugin, or custom code that you created?
What is the translation method that you are using?
Are you using WPML's Translation Editor or the WordPress editor to translate the posts?

Thanks,
Itamar.

August 20, 2019 at 12:49 pm #4423707

Willem

We only use a bare minimum of plugins, see attached screenshot.
The CPT is created by custom code, but nothing special in particular:

	register_post_type(
		EZZYS_VACANCIES_CPT,
		array(
			'labels' => array(
				'name' => __('Vacancy', EZZYS_ADMIN_TEXTDOMAIN),
				'singular_name' => __('Vacancy', EZZYS_ADMIN_TEXTDOMAIN),
				'all_items' => __('All Vacancies', EZZYS_ADMIN_TEXTDOMAIN),
				'menu_name' => __('Vacancies', EZZYS_ADMIN_TEXTDOMAIN)
			),
			'public' => true,
			'publicly_queryable' => true,
			'show_ui' => true, 
			'show_in_menu' => true, 
			'show_in_rest' => true,
			'menu_position' => 30,
			'capability_type' => 'post',
			'hierarchical' => false,
			'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author'),//, 'page-attributes'
			'has_archive' => false, 
			'rewrite' => array('slug' => __('vacancies', EZZYS_ADMIN_TEXTDOMAIN) . '/%'.EZZYS_VACANCIES_TAX.'%', 'with_front' => false, 'pages' => true),
			'query_var' => true,
			'menu_icon' => 'dashicons-id',
		)
	);

for now i think i 'resolved' the issue by adding

add_action('save_post', 'flush_rewrite_rules');

the translations are added by clicking on the '+' button in wp-admin in the english-flag-column. I don't think there are any problems with translating wrong, i think the problem might be caused by the 'rewrite' part when registering our CPT.

August 21, 2019 at 11:17 am #4430659

Itamar
Supporter

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

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

Hi.

I'm glad that you have found a workaround for this issue. It is hard for me to help you when custom code is involved. This would be out of the scope of this support forum. Nevertheless, you might find helpful information et the following link where we present a known related issue (Not a bug). https://wpml.org/errata/htaccess-is-rewritten-with-language-folder/

Please let me know if you have further questions about this case.

Regards,
Itamar.

The topic ‘[Closed] 404 for custom post type’ is closed to new replies.