Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is managing a bilingual site with a custom post type 'News' created using Advanced Custom Fields and Elementor Pro. The archive pages translate correctly, but the author archive pages do not link properly in the language switcher, redirecting to the homepage of the opposite language instead of linking to the corresponding translated author archive page.
Solution:
We escalated the issue to our 2nd tier of support. They provided a workaround involving adding the following code to the functions.php file:

function include_custom_post_types_in_author_archive( $query ) {<br />    if ( $query->is_author() && $query->is_main_query() ) {<br />        $post_types = $query->get('post_type');<br />        if (!is_array($post_types)) {<br />            $post_types = array($post_types);<br />        }<br />        $post_types[] = 'news';<br />        $query->set('post_type', $post_types);<br />    }<br />}<br />add_action( 'pre_get_posts', 'include_custom_post_types_in_author_archive' );

After implementing this code, double-check if the issue with the language switcher on the author archive pages is resolved.

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. Should you need further assistance, please do not hesitate to open a new support ticket or visit our support forum at WPML Support Forum.

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

Last updated by Carlos Rojas 1 year, 1 month ago.

Assisted by: Carlos Rojas.

Author Posts
May 31, 2024 at 10:11 am

Emma Hewson

Background of the issue:
I am managing a bilingual site (English & Welsh) with a custom post type 'News' created using Advanced Custom Fields and Elementor Pro. The archive pages translate correctly, but the author archive pages do not link properly in the language switcher. I have temporarily fixed the issue using JavaScript on the live site but have set up a staging site without the workaround for testing. Staging site: hidden link, Author archive (English): hidden link, Author archive (Welsh): hidden link

Symptoms:
The language switcher on the author archive pages does not link between the English and Welsh versions of the page. Instead, it redirects to the homepage of the opposite language, behaving as if a translation does not exist.

Questions:
Why isn't the language switcher working correctly on the author archive pages?
How can I prevent this issue from occurring in the future without using JavaScript?

May 31, 2024 at 10:35 am
May 31, 2024 at 10:39 am #15691803

Carlos Rojas
WPML Supporter since 03/2017

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

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

Hi there,

I have escalated this ticket to our 2nd tier of support. I will get back to you as soon as I get feedback from our 2nd tier specialists.

Thank you very much for your patience and understanding!

June 4, 2024 at 8:55 am #15700519

Carlos Rojas
WPML Supporter since 03/2017

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

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

Hi there,

Our 2nd tier specialists have found a workaround. Please paste the following code in the functions.php file:

function include_custom_post_types_in_author_archive( $query ) {
    if ( $query->is_author() && $query->is_main_query() ) {
        $post_types = $query->get('post_type');
        if (!is_array($post_types)) {
            $post_types = array($post_types);
        }
        $post_types[] = 'news';
        $query->set('post_type', $post_types);
    }
}
add_action( 'pre_get_posts', 'include_custom_post_types_in_author_archive' );

- Then double-check if the issue disappeared

June 7, 2024 at 9:35 am #15714487

Emma Hewson

That worked perfectly, thanks to you and the team for your help

June 7, 2024 at 9:55 am #15714645

Carlos Rojas
WPML Supporter since 03/2017

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

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

I'm glad to hear that the issue is solved 🙂

Please don't hesitate to contact us if you need our help in the future with WPML. We will be more than happy to help.
Best regards,
Carlos