I created a custom post type product
and added a taxonomy product_category
for it, with hierarchical
set to true since I wanted parent categories (use case: fruits > berries etc).
The admin list for product
(/wp-admin/edit.php?post_type=product) only shows products with a parent taxonomy but none with a child taxonomy, even though the counter for product
s shows the right number.
When navigating to /wp-admin/edit.php?product_category=berries&post_type=product, it shows those missing posts.
What am I doing wrong? Below is the responsible code:
$taxonomy = [
'hierarchical' => true,
'labels' => [ ... ],
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => true,
'refersTo' => 'product'
];
$postType = [
'labels' => [ ... ],
'supports' => [
'title',
'editor',
'thumbnail',
'custom-fields',
'revisions'
],
'taxonomies' => [ 'product_category' ],
'rewrite' => true,
'public' => true,
'has_archive' => true
];
function flush_rewrite_rules () {
global $wp_rewrite;
$wp_rewrite->flush_rules();
});
add_action('init', 'flush_rewrite_rules' );
function register_products_taxonomy () {
register_taxonomy( 'product_category', 'product', $taxonomy);
flush_rewrite_rules();
}
add_action( 'init', 'register_products_taxonomy', 5 )
function register_products_type () {
register_post_type( 'product', $postType );
flush_rewrite_rules();
}
add_action( 'init', 'register_products_type' );
register_post_type( 'product', $postType );
Something is wrong with the pasted code, there are more mistakes like:'rewrite' => true 'public' => true,
instead of'rewrite' => true, 'public' => true,
Code like this wouldn't parse - please check once again the code sample and correct the obvious errors.