grappler / polylang-slug

A unique post slug within the language in Polylang. This allows for a page to have same/identical slug in multiple languages.
268 stars 84 forks source link

Redirect to default languages url #5

Closed seokomail closed 9 years ago

seokomail commented 9 years ago

Hi. I tried to use your plugin. Need the same slug for different languages. Installed plugin. Created 2 pages with the same slug, but have redirection from http://tour.wss.pp.ua/en/step-2/ to http://tour.wss.pp.ua/step-2/

Can you help to solve the problem?

mirsch commented 9 years ago

I have the same issue. The main problem is polylang does not add the lang parameter to the rewrite rules for pages. On the other hand WordPress uses a different method to load pages compared to posts. (get_page_by_path()) So we need to modify the rewrite rules to get the lang parameter and hook into pre_get_posts to force the right page. I've created a "quick and dirty" solution to fix this for my needs. It may have side effects but in my settup it works like a charm. You can test it if you like: https://github.com/mirsch/polylang-slug/tree/fixpages

seokomail commented 9 years ago

Thank you, mirsch!!! LIKE A CHARM! grappler, mirsch you are the gods. Thx men.

mirsch commented 9 years ago

@grappler have you looked into this? Should I create a pull request?

grappler commented 9 years ago

I am still looking into it. For some reason it was working for me on one site.

I have been testing some old code that I removed but it is failing and I am not sure why. https://github.com/grappler/polylang-slug/commit/dbf059027a1829eb8cd3e3677db59da0afba3efb

mirsch commented 9 years ago

I'm not sure if this worked in previous versions of polylang, but in the current version there is no lang parameter in the rewrite rules for pages. It looks something like that: [(en)/(.?.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[2]&page=$matches[3] thats why pll_current_language() always returns the default language for pages. Without any parameter which indicates the language it's not possible to select the right page.

grappler commented 9 years ago

@mirsch & @seokomail Can you try with the latest version? A friend made a PR which should fix the issue.

mirsch commented 7 years ago

@arpa463x thank you, but give the Kudos to @grappler! He's the one who wrote and maintain the plugin.