I have a custom post type that has a custom taxonomy which functions as the main hierarchical structure for this custom post type. I am experiencing some behavior that I can't explain though.
This hierarchical structure is 3 levels deep as following:
main
-section
--subsection
The idea is that every custom post type is added to a subsection so that a book>chapter-like structure forms. I have made several restrictions to the custom post type admin page so that it's only possible to add new custom post types to subsections (and this part is working well).
The problem is that for main/sections filters the custom post type that are in certain subsections won't show. This isn't just in my custom frontend archives but also in the WordPress backend, which makes it seem like quite a fundamental problem. For the backend of this custom post type I have also added some pretty standard filters for the taxonomies. When I select the --subsection depth in this filter, the posts that have this --subsection show as expected. But when select the main or -section of the aforementioned --subsection, nothing shows. All of these taxonomies have been added by a user, so I'm not sure what or if he has done something differently with adding these problematic --subsections.
Some plugins that could be related and are active:
- WPML Multilingual CMS
- Category Order and Taxonomy Terms Order
- CPT-onomies: Using Custom Post Types as Taxonomies
Naturally I've tried disabling them.
My CPT registration:
add_action('init', function() {
global $plugin_base_dir;
// Argumenten voor registreer functie
$args = array(
'labels' => array(
'name' => 'Rules',
'singular_name' => 'Rule',
'add_new' => 'New rule',
'add_new_item' => 'Add new rule',
'edit_item' => 'Edit rule',
'new_item' => 'New rule',
'view_item' => 'View rule',
'search_items' => 'Search rules',
'not_found' => 'No rules found',
'not_found_in_trash' => 'No rules found in trash'
),
'query_var' => 'rule',
'rewrite' => false,
'taxonomies' => array(
'rlt_rule_headline',
'rlt_rule_topic',
'rlt_rule_year'
),
'public' => true,
'publicly_queryable' => true,
'menu_icon' => '',
'show_ui' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array(
'title',
'editor'
)
);
// Registreer de Custom Post Type
register_post_type('rlt_rule', $args);
});
The problematic taxonomy registration:
register_taxonomy(
'rlt_rule_headline',
'rlt_rule',
array(
'labels' => array(
'name' => 'Headlines',
'singular_name' => 'Headline',
'add_new_item' => 'Add headline',
'new_item_name' => "New headline"
),
'rewrite' => array(
'slug' => 'headline',
'with_front'=> false,
'feed'=> true
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true
)
);
My added backend filter:
$filter_taxonomy = 'rlt_rule_headline';
wp_dropdown_categories(
array(
'show_option_all' => 'Show all headlines',
'taxonomy' => $filter_taxonomy,
'name' => $filter_taxonomy,
'orderby' => 'name',
'selected' => ( isset( $wp_query->query[$filter_taxonomy] ) ? $wp_query->query[$filter_taxonomy] : '' ),
'hierarchical' => true,
'depth' => 3,
'show_count' => false,
'hide_empty' => true,
)
);
The filter is default. I haven't added a function to catch it and handle anything. So it just adds query_vars and filters like a normal archive. The same goes with the frontend archive.