Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No luck with translations working for slugs #31

Closed
SeenNotHurd opened this issue Nov 9, 2015 · 4 comments
Closed

No luck with translations working for slugs #31

SeenNotHurd opened this issue Nov 9, 2015 · 4 comments

Comments

@SeenNotHurd
Copy link

Hey this seems like a great plugin... buuuuuuut I can't seem to get it to work at all?

I have followed the instructions (it might be time to update them? Can't find any info about implementing translations for custom archive slugs...) but I seem to be missing something. As soon as I set everything up, the re-writing of the URLs works perfectly, but all the urls give me a 404, even english (which I have set up in the filter hook) which is the same url is failing.

I know this isn't a support forum or anything but hoping someone can give me a nudge in the right direction?

function orn_cpt_slug_translate($post_type_translated_slugs) {
    $post_type_translated_slugs = array(
        'orn_article' => array(
            'en' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'article',
                ),
            ),
            'fi' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'artikkeli',
                ),
            ),
        ),
    );
    return $post_type_translated_slugs;
}

add_filter('pll_translated_post_type_rewrite_slugs', 'orn_cpt_slug_translate');

WP 4.3.1
Polylang 1.7.11
WP Polylang translate rewrite slugs 0.3.6

Thanks in advance for any advice

@kossmann
Copy link

I just used this plugin to to translate a CPT slug in a project, and everything worked great.

Not sure if I understood your problem, but have you tried to access the 'Permalink' page in Admin to update the permalink structure? Maybe this does the trick for you.

@PaulMorel
Copy link

I'm having the same problem when I set the URL modifications option in Polylang to

The language is set from content

If I set it to:

The language is set from the directory name in pretty permalinks

The plugin works as advertized. If I'm not mistaken the function that deals with this is get_post_type_archive_link and there's a check for Polylang's URL Modifications options from line 236 to line 244 and the appropriate action.

if (
// If the "URL modifications" is set to "The language is set from the directory name in pretty permalinks".
$polylang->options['force_lang'] == 1
// If NOT ("Hide URL language information for default language" option is
// set to true and the $lang is the default language.)
&& !($polylang->options['hide_default'] && $lang == pll_default_language())
) {
$struct = $lang . '/' . $struct;
}

If you have it set otherwise, it should skip this check and still create a proper URL. However it doesn't seem to be the case.

Here's my code:

add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
    $post_type_translated_slugs = array(
        'product' => array(
            'fr' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'produit',
                ),
            ),
            'en' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'product',
                )
            )
        )
    );
    return $post_type_translated_slugs;
});

WP 4.4
Polylang 1.7.12
WP Polylang translate rewrite slugs 0.3.6

I tried to troubleshoot, but I couldn't see anything wrong with the plugin.

@satoristudio
Copy link

I've posted a possible solution for this in #32 ;)

@SeenNotHurd
Copy link
Author

It turned out to be because of having rewrites in both my custom post setup AND in the file above. Best to only have it once?

Might also be the order I was loading php files. Need to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants