• Hi all, i’m very newbie here and wp in total. Down here is the problem and a dirty solution, which possibly should go to tickets (i actually don’t now there to talk about).

    In my project commercial theme with custom post types is used. Also i use utf-8 slugs for url’s with russian words. Bugged custom post type options as follows:

    register_post_type( 'cstm',
        array(
    	'label' => __('Custom Items', 'cstm_theme'),
    	'labels' => array(
    		'add_new' => __('Add to Custom', 'cstm_theme'),
    		'add_new_item' => __('Add New Custom Item', 'cstm_theme'),
    		'new_item' => __('New Custom Item', 'cstm_theme'),
    	),
    	'singular_label' => __('Custom Item', 'cstm_theme'),
    	'_builtin' => false,
    	'public' => true,
    	'show_ui' => true,
    	'show_in_nav_menus' => true,
    	'menu_position' => 5,
    	'hierarchical' => true,
    	'capability_type' => 'page',
    	'menu_icon' => get_template_directory_uri() . '/includes/images/icon_cstm.png',
    	'rewrite' => array(
    		'slug' => __('cstm-view', 'cstm_theme'),
    		'with_front' => FALSE,
    	),
    	'supports' => array(
    			'title',
    			'editor',
    			'thumbnail',
    			'excerpt',
    			'custom-fields',
    			'comments')
    		)
    );

    Where is also one custom non-hierarchical tax type, but it seems doesn’t matter. What does matter is permalink standard option:

    /%category%/%postname%/

    The problem is – links like /[cstm-view]/[some-item]/ (there is [] for utf-8 slugs) don’t work. The source of the problem is in canonical.php. $requested_url of function redirect_canonical always fully url encoded while $redirect_url after line 198 (this is why permalink option value is important):

    $redirect_url = get_permalink($wp_query->get_queried_object_id());

    contains [cstm-view] part in non-encoded format due to permalink generation engine. So at several next lines $redirect_url != $requested_url appears to be TRUE that leads to wrong redirection(s).

    My minor solution patch – to add the following line after line 198 (in if block):

    $redirect_url = urldecode($redirect_url) == urldecode($requested_url) ? $requested_url : $redirect_url;

    I also tried to set up slugs in url encoded format like this
    'slug' => urlencoded(__('cstm-view', 'cstm_theme'))
    but it didn’t work too for some other reasons i didn’t try to find out.

    Sorry for a lot of letters. May be i’m wrong or missing some important detail. Thanks for every response!

  • The topic ‘Custom post type with utf-8 slug permalink trouble – ticket candidate?’ is closed to new replies.