I’m using WPML plugin to translate my site.
I have a custom post type called “vinos” and I use this args:

$args = array( 
            'labels' => $labels,
            'hierarchical' => false,
            'supports' => array('title', 'thumbnail'),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 6,
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => 'nuestros-vinos/catalogo',
            'query_var' => true,
            'can_export' => true,
            'capability_type' => 'post',
            'rewrite' => array('slug' => 'nuestros-vinos/catalogo/marcas/%marcas%')
    );
    register_post_type('vinos', $args);

The problem is that I can’t translate my string “nuestros-vinos/catalogo/marcas” to english and for that reason my urls are:

www.domain.com/nuestros-vinos/catalogo/ ———> show all my list of wines in spanish
www.domain.com/en/nuestros-vinos/catalogo/ ——> show all my list of wines in english

but I would like that in english version, the url was:

www.domain.com/en/our-wines/catalog/

I’m trying to use rewrite rules:

add_filter('generate_rewrite_rules', 'customposttype_rewrites');
function customposttype_rewrites($wp_rewrite) {
    $newrules = array();
    $newrules['en/our-wines/catalog/?$'] = 'en/index.php?post_type=vinos';
    $wp_rewrite->rules = $newrules + $wp_rewrite->rules;
}

But it doesn’t work, always page not found.

How can I do it?

Thanks.

2 Answers
2

this will not work:

'en/index.php?post_type=vinos'

there is no en/index.php, it has to be:

'index.php?post_type=vinos'

if you need to detect en in the path, add a query var, then set that query var in your rewrite:

function wpa_query_vars( $qvars ) {
    $qvars[] = 'wpa_lang';
    return $qvars;
}
add_filter( 'query_vars', 'wpa_query_vars' );

then in your rewrite rule:

$newrules['en/our-wines/catalog/?$'] = 'index.php?post_type=vinos&wpa_lang=en';

Leave a Reply

Your email address will not be published. Required fields are marked *