This thread is resolved. Here is a description of the problem and solution.
Problem:
The client needed to translate archive pages for custom post types (CPTs) and deactivate/delete unwanted indexed translated archive pages.
Solution:
We recommended manually registering the CPTs to avoid issues with translations and indexing. Additionally, the client provided a custom code snippet to disable the archive slug for some CPTs in all languages other than the default. Here is the code snippet:
function sws_remove_cpt_archive_for_other_languages() {<br /> $current_language = apply_filters('wpml_current_language', null);<br /> $default_language = apply_filters('wpml_default_language', null);<br /> if ($current_language !== $default_language) {<br /> add_action('template_redirect', 'sws_disable_cpt_archive');<br /> }<br />}<br />function sws_disable_cpt_archive() {<br /> $cpts_to_disable = array('cpt1', 'cpt2', 'cpt3');<br /> foreach ($cpts_to_disable as $cpt) {<br /> if (is_post_type_archive($cpt)) {<br /> wp_redirect(apply_filters('wpml_home_url', home_url()));<br /> exit();<br /> }<br /> }<br />}<br />add_action('init', 'sws_remove_cpt_archive_for_other_languages', -1);
We also suggested modifying the
\MBCPT\PostTypeRegister::get_post_types
method in
wp-content/plugins/meta-box-aio/vendor/meta-box/mb-custom-post-type/src/PostTypeRegister.php
by setting
suppress_filters = false
. This ensures
get_posts
will fetch posts only in the specific language by bypassing WPML filters.
If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket.
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 17 replies, has 2 voices.
Last updated by 6 months, 2 weeks ago.
Assisted by: Bruno Kos.