0

On a website using WPML in last version, I have a Custom Post Type using an archive page, called archive-agenda.php. CPT is defined with this code :

register_post_type('agenda', array(
    'label' => __('Agenda'),
    'public' => TRUE,
    'menu_position' => 22,
    'rewrite' => array(
        'slug' => _x( 'agenda', 'URL slug', 'cluster' ),
        'with_front' => FALSE
    ),
    'has_archive' => TRUE,
    'supports' => array('title', 'editor')
));

The default language is french, secondary language is english. In WPML i translated the english slug by calendar. /agenda and /en/calendar are working great, but when I try to reach the archive page using /agenda/archives/2014, it's working only in french, english version (/en/calendar/archives/2014) return a 404 error.

I'm using custom rewrite rules for the archive page :

add_filter('generate_rewrite_rules', 'my_rewrite', 11);
function my_rewrite($wp_rewrite)
{
    $wp_rewrite->rules = array_merge(array(
        '^agenda/archives/([^/]*)/?$' => 'index.php?post_type=agenda&agenda_annee=$matches[1]',
        '^en/calendar/archives/([^/]*)/?$' => 'index.php?post_type=agenda&agenda_annee=$matches[1]'
}

I tried various priority values (9,11,none), with and without the en/ for the english rule, but this is not making any difference.

Am I missing something ?

Thanks in advance.

UPDATE

I manage to get the page working by using this rule in .htaccess :

RewriteRule ^en/calendar/archives/([0-9]*)/?$ /en/index.php?post_type=agenda&agenda_annee=$1 [R,L]

Problem is now that I get an ugly URL with that. If I remove the R flag, it's not working and send me a 404.

  • The answer is don't use same name's for slugs/cats/taxonomies/pages or posts in a multi language WP site or you will have major problems. WP cannot figure out what slug you want to show, seriously don't do this , it's a nightmare. – Wyck Oct 31 '14 at 1:01
  • I had different names before for english and french, I changed them to see if it would make any difference : it don't. So this is not the problem. – vard Nov 3 '14 at 14:25
  • Until something breaks. – Wyck Nov 3 '14 at 19:54
  • Well. Now I'm using distinct slugs for english and french (calendar vs agenda). See updated post. Still have the same issue, nothing changed. – vard Nov 6 '14 at 9:57
  • Did you flush your rewrite rules after you made the changes? – Wyck Nov 7 '14 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.