Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

golbarg on "[Plugin: Polylang] CPT archive navigation language switcher"

$
0
0

Hi,

I have a CPT and am using the archive pages for them, and there seems to be a problem with the navigation language switcher.

When I am in /fr/my-fr, the link is /en/my-fr instead of /en/my-en

I have defined the slugs in the CPT with:

if(get_locale() == 'fr_FR')
{
$args = array(
    'rewrite' => array('slug' => 'my-fr'),
    // more
);
}
else
{
$args = array(
    'rewrite' => array('slug' => 'my-en'),
    // more
);
}
register_post_type( 'my-cpt' , $args );

I have tried using "Polylang - Translate URL Rewrite Slugs" plugin in combination with Polylang, using the following piece:

add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
    // Add translation for "my-cpt" post type.
    $post_type_translated_slugs = array(
        'my-cpt' => array(
            'fr' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'my-fr',
                ),
            ),
            'en' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'my-en',
                ),
            ),
        ),
    );
    return $post_type_translated_slugs;
});

With this I get the right URLs for:
/en/my-en/cpt-post-en
/fr/my-fr/cpt-post-fr

However, when I'm on the archive page (/en/my-en), the link to the other language is missing the language (/my-fr instead of /fr/my-fr) and returns a 404.

I have also tried using

add_filter('pll_get_post_types', 'my_pll_get_post_types');
function my_pll_get_post_types($types) {
	return array_merge($types, array('my-cpt' => 'my-cpt'));
}

I can't seem to find a way to make this work as it should, and I did try flushing the permalinks.

Any help?

PLL 1.6
(PLL-TURS 0.3.1)
WP 4.0

https://wordpress.org/plugins/polylang/


Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>