I am currently running against a wall while dealing with custom taxonomies. My intent is so use a taxonomy for categories for my custom post type, as to not interfere with the default categories used in wordpress. I've got that working for now and can retrieve a custom post's categories using this method. The problem I am running into is displaying the posts when clicking on a category, meaning I probably have an issue with the archive page, as far as I've been told.
My current CPT setup - I am using a custom class to create post types and taxonomies, the options are more relevant:
$eunv_tilemanager = new Cnm_CPT(
'eunv_tilemanager',
array(
'name' => __('Tilemanager', 'eunv'),
'singular_name' => __('Tilemanager', 'eunv'),
'name_admin_bar' => __('Tilemanager', 'eunv'),
'add_new_item' => __('Add new tile', 'eunv'),
'edit_item' => __('Edit tile', 'eunv'),
'search_items' => __('Search tiles', 'eunv'),
'not_found' => __('No tiles found', 'eunv'),
'not_found_in_trash' => __('No tiles found in Trash', 'eunv'),
),
array(
'menu_icon' => get_template_directory_uri() . "/assets/dist/img/eunv-logo-menu.png",
'show_ui' => true,
'public' => true,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => false,
'has_archive' => false,
'hierarchical' => false,
'exclude_from_search' => true,
'show_in_nav_menus' => false,
'supports' => array( 'title', 'thumbnail' ),
)
);
$eunv_tilemanager->add_taxonomy(
'eunv_tilemanager_cat',
array(
'name' => __('Categories', 'eunv'),
'singular_name' => __('Category', 'eunv'),
'menu_name' => __('Categories', 'eunv'),
),
array(
'show_ui' => true,
'public' => true,
'publicly_queryable' => false,
'query_var' => true,
'rewrite' => array(
'slug' => 'posts'
),
'has_archive' => true,
'hierarchical' => true,
'exclude_from_search' => true,
'show_in_nav_menus' => false,
'show_admin_column' => true
)
);
I've tried around changing the taxonomies rewrite, query_var, exclude_from_search and public options. I am trying to get a link like '127.0.0.1/wp-project/posts/cat-name' to work, where 'posts' isn't the word I necessarily need as slug, it could be anything.
Right now, after using the following snippet and with the above setup, I can call that exact link, but I get redirected to the base page immediately:
add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
I would appreciate any form of help, as I'm kind of running out of ideas and haven't found any applicable solution to my problem.
Thanks in advance and best regards
Nick