Custom taxonomy throw error 404
So in my homework I was given code example and it works for teacher, but not for me. So from what i understand that I'm creating custom post type and custom taxonomy for it, also there is filter that replaces my %gaming_genre_new% with created category. And it works on custom post type stage, but it breaks when I add taxonomy. I can access for example my archive gaming and even created with taxonomy genres in it, but when i want to view particular post, it just throws error 404.
add_action( 'init', 'create_taxonomy' );
function create_taxonomy(){
register_taxonomy( 'gaming_genre_new', [ 'gaming' ], [
'label' = '', // определяется параметром $labels-name
'labels' = [
'name' = 'Game genres',
'singular_name' = 'Game genre',
'search_items' = 'Search Genres',
'all_items' = 'All Genres',
'view_item ' = 'View Genre',
'parent_item' = 'Parent Genre',
'parent_item_colon' = 'Parent Genre:',
'edit_item' = 'Edit Genre',
'update_item' = 'Update Genre',
'add_new_item' = 'Add New Genre',
'new_item_name' = 'New Genre Name',
'menu_name' = 'Genre',
'back_to_items' = '← Back to Genre',
],
'description' = '', // описание таксономии
'public' = true,
// 'publicly_queryable' = null, // равен аргументу public
// 'show_in_nav_menus' = true, // равен аргументу public
// 'show_ui' = true, // равен аргументу public
// 'show_in_menu' = true, // равен аргументу show_ui
// 'show_tagcloud' = true, // равен аргументу show_ui
// 'show_in_quick_edit' = null, // равен аргументу show_ui
'hierarchical' = true,
'rewrite' = array('slug'='gaming/%gaming_genre_new%','with_front'='false'),
//'query_var' = $taxonomy, // название параметра запроса
'capabilities' = array(),
'meta_box_cb' = null, // html метабокса. callback: `post_categories_meta_box` или `post_tags_meta_box`. false — метабокс отключен.
'show_admin_column' = false, // авто-создание колонки таксы в таблице ассоциированного типа записи. (с версии 3.5)
'show_in_rest' = null, // добавить в REST API
'rest_base' = null, // $taxonomy
// '_builtin' = false,
//'update_count_callback' = '_update_post_term_count',
] );
}
// создание своего типа записи
add_action( 'init', 'register_post_types' );
function register_post_types(){
register_post_type( 'gaming', [
'label' = null,
'labels' = [
'name' = 'Gaming', // основное название для типа записи
'singular_name' = 'Gaming', // название для одной записи этого типа
'add_new' = 'Add Gaming Post', // для добавления новой записи
'add_new_item' = 'Adding Gaming Post', // заголовка у вновь создаваемой записи в админ-панели.
'edit_item' = 'Edit Gaming Post', // для редактирования типа записи
'new_item' = 'New Gaming Post', // текст новой записи
'view_item' = 'View Gaming Post', // для просмотра записи этого типа.
'search_items' = 'Search Gaming Post', // для поиска по этим типам записи
'not_found' = 'Не найдено', // если в результате поиска ничего не было найдено
'not_found_in_trash' = 'Не найдено в корзине', // если не было найдено в корзине
'parent_item_colon' = '', // для родителей (у древовидных типов)
'menu_name' = 'Gaming', // название меню
],
'description' = '',
'public' = true,
// 'publicly_queryable' = null, // зависит от public
// 'exclude_from_search' = null, // зависит от public
// 'show_ui' = null, // зависит от public
// 'show_in_nav_menus' = null, // зависит от public
'show_in_menu' = null, // показывать ли в меню адмнки
// 'show_in_admin_bar' = null, // зависит от show_in_menu
'show_in_rest' = null, // добавить в REST API. C WP 4.7
'rest_base' = null, // $post_type. C WP 4.7
'menu_position' = 4,
'menu_icon' = null,
//'capability_type' = 'post',
//'capabilities' = 'post', // массив дополнительных прав для этого типа записи
//'map_meta_cap' = null, // Ставим true чтобы включить дефолтный обработчик специальных прав
'hierarchical' = true,
'supports' = [ 'title', 'editor', 'author'], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
'taxonomies' = ['gaming_genre_new'],
'has_archive' = 'gaming',
'rewrite' = array('slug'='gaming/%gaming_genre_new%','with_front' = 'false'),
'query_var' = true,
] );
}
add_filter('post_type_link', 'gaming_permalink', 1,2);
function gaming_permalink($permalink,$post){
if (strpos( $permalink, '%gaming_genre_new%' ) === false )
return $permalink;
$terms=get_the_terms($post,'gaming_genre_new');
if ( ! is_wp_error( $terms ) !empty($terms) is_object($terms[0]))
$term_slug=array_pop($terms)-slug;
else
$term_slug='no-gaming-genre';
return str_replace('%gaming_genre_new%',$term_slug,$permalink);
}
UPD: forgot to mention that i tried: resetting permalinks and flush_rewrite_rules. And that I'm using openserver.
Topic custom-taxonomy 404-error Wordpress
Category Web