404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
-
I am using a custom post type and rewrite rule for nested taxonomies. My permalink structure: site.ru / catalog / term-1 / term-2 / post_name
If my taxonomies are in Cyrillic: site.ru / catalog / term-Cyrillic-1 / term-Cyrillic-2 / post_name i get 404 error for term-Cyrillic-2 term-Cyrillic-1 no mistake.
Sorry for my English. You are my last hope.
<?php /* * Plugin Name: MOD * Description: DEV */ /** * Создание произвольного типа записи * - register_post_types() */ add_action('init', 'register_post_types', 0); function register_post_types() { // тип записи register_post_type('mod_services', array( 'labels' => array('name' => __('Товары')), 'public' => true, 'show_in_menu' => true, 'show_in_rest' => null, 'rest_base' => null, 'hierarchical' => false, 'supports' => array('title', 'editor', 'thumbnail'), 'has_archive' => true, 'rewrite' => array('slug' => 'catalog', 'with_front' => false), 'query_var' => true, )); // таксономия register_taxonomy('mod_services_catalog', array('mod_services'), array( 'labels' => array('name' => __('Категории')), 'public' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'catalog', 'hierarchical' => true, 'with_front' => false), 'capabilities' => array(), 'meta_box_cb' => null, 'show_admin_column' => false, 'show_in_rest' => null, 'rest_base' => null, )); } /** * Изменяем структуру ссылок записей * - products_permalink() */ add_filter('post_type_link', 'products_permalink', 1, 2); function products_permalink($permalink, $post) { if (strpos($permalink, 'catalog') === false) return $permalink; $terms = get_the_terms($post, 'mod_services_catalog'); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) { $taxonomy_slug = get_term_parents_list($terms[0]->term_id, 'mod_services_catalog', array( 'separator' => '/', 'format' => 'slug', 'link' => false, 'inclusive' => true )); $taxonomy_slug = trim($taxonomy_slug, '/'); } else { $taxonomy_slug = 'categories'; } return str_replace('catalog', 'catalog/' . $taxonomy_slug, $permalink); } /** * Создаём новые правила перезаписи + * - taxonomy_slug_rewrite() */ add_filter('generate_rewrite_rules', 'taxonomy_slug_rewrite'); function taxonomy_slug_rewrite($wp_rewrite) { $rules = array(); $taxonomies = get_terms(array( 'taxonomy' => 'mod_services_catalog', 'hide_empty' => false )); foreach ($taxonomies as $taxonomy) { $taxonomy_slug = get_term_parents_list($taxonomy->term_id, 'mod_services_catalog', array( 'separator' => '/', 'format' => 'slug', 'link' => false, 'inclusive' => true )); $rules['^catalog/' . $taxonomy_slug . '?$'] = 'index.php?' . $taxonomy->taxonomy . '=' . $taxonomy->slug; } $rules['^catalog/([^/]*)/?$'] = 'index.php?mod_services_catalog=$matches[1]'; $rules['^catalog/(.+?)/page/?([0-9]{1,})/?$'] = 'index.php?mod_services_catalog=$matches[1]&paged=$matches[2]'; $rules['^catalog/(.+?)/([^/]*)/?$'] = 'index.php?mod_services=$matches[2]'; $wp_rewrite->rules = $rules + $wp_rewrite->rules; } /** * Обновляем правила перезаписи при создании/удалении/изменении таксономий * - hc_reset_rewrite_rules() */ add_action('created_mod_services_catalog', 'hc_reset_rewrite_rules'); add_action('delete_mod_services_catalog', 'hc_reset_rewrite_rules'); add_action('edited_mod_services_catalog', 'hc_reset_rewrite_rules'); add_action('save_mod_services_catalog', 'hc_reset_rewrite_rules'); function hc_reset_rewrite_rules() { flush_rewrite_rules(); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?’ is closed to new replies.