$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>url rewriting - Why isn't my custom post type archive URL translating?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

url rewriting - Why isn't my custom post type archive URL translating?

matteradmin9PV0评论

I've god a 'wine' custom post type, created with rewriting options:

'rewrite' => array(
  'slug' => __('vini', 'fdr'),
  'with_front' => false,
  'pages' => false
),

So the slug should translate. I've got an en-GB.po/mo where I'm translating 'vini' to 'wines'.

Though, the URL generated under translations are not translated:

  • original: [base url]/vini/teroldego-morei/

  • translated: [base url]/en/vini/teroldego-morei/

What I would like (and I guess, should be): [base url]/en/wines/teroldego-morei/

So what? The official docs say 'Should be translatable'. Well, it is, but it seems the whole thing doesn't work.

I've god a 'wine' custom post type, created with rewriting options:

'rewrite' => array(
  'slug' => __('vini', 'fdr'),
  'with_front' => false,
  'pages' => false
),

So the slug should translate. I've got an en-GB.po/mo where I'm translating 'vini' to 'wines'.

Though, the URL generated under translations are not translated:

  • original: [base url]/vini/teroldego-morei/

  • translated: [base url]/en/vini/teroldego-morei/

What I would like (and I guess, should be): [base url]/en/wines/teroldego-morei/

So what? The official docs say 'Should be translatable'. Well, it is, but it seems the whole thing doesn't work.

Share Improve this question edited Jul 26, 2017 at 11:56 Max Yudin 6,3982 gold badges26 silver badges36 bronze badges asked Jul 26, 2017 at 9:58 Luca ReghellinLuca Reghellin 1,6522 gold badges21 silver badges45 bronze badges 2
  • Are you sure that you get the right string from your po/mo files? I would echo that somewhere to check. Just an idea, may you are sure about it. – Luckyfella Commented Jul 26, 2017 at 11:50
  • Also, flush rewrite rules every time you change something regarding them. Go to Settings -> Permalinks and click Save without changing anything. – Max Yudin Commented Jul 26, 2017 at 11:58
Add a comment  | 

1 Answer 1

Reset to default 0

UPDATE 1:

I haven't find a solution yet (other than using Polylang Pro). But I must add that my original question was partially wrong, since the rewrite option is for the single page url, not the archive one.

Custom post type archive has its own slug and it's the has_archive option (can be boolean or string). So basically can be something like this:

'has_archive' => __('products','mytxtdomain')

Though, just as the rewrite url, it doesn't work, and probably the answer below is still valid.


The answer is: it's not possible.

Falks or the Polylang Pro crew explained me the reason why:

If you flush your rewrite rules while the locale is Italian, your slug is evaluated to 'vini'. If you flush them while the locale is English, the slug is evaluated to 'wine'. So, in the first case, the rewrite rule pattern is:

vini/([^/]+)(?:/([0-9]+))?/?$

and in the second case, it is

wine/([^/]+)(?:/([0-9]+))?/?$

But you never have both at the same time. So only one is working.

Post a comment

comment list (0)

  1. No comments so far