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 products 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();
}, 5 );
add_action( 'init', 'register_products_taxonomy' );

function register_products_type () {
  register_post_type( 'product' ), $postType );
  flush_rewrite_rules();
}
add_action( 'init', 'register_products_type' );

Read more here: Custom post types with child taxonomy not visible in admin


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: