how to fix url issue of wordpress nested subcategory archive pages

Solution:

You have to do a couple of things to achieve what you want.

  1. Add custom rewrite rules: First you have to add the custom rewrite rules to detect a subcategory. WordPress by default won’t do that.
  function theme_custom_rewrites() {
    add_rewrite_tag("%parent_category_name%", "([a-z0-9\-_]+)");
    add_rewrite_rule('^category/([a-z0-9\-_]+)/([a-z0-9\-_]+)/?', 'index.php?parent_category_name=$matches[1]&category_name=$matches[2]', 'top');

    add_rewrite_rule('^category/([a-z0-9\-_]+)/?', 'index.php?category_name=$matches[1]', 'top');
  }

  add_action('init', 'theme_custom_rewrites'); 
  1. Add the 404 status and template load code:
function load_404_page_for_subcategory_pages() {
  global $wp_query;

  $category_slug = get_query_var('category_name');
  $parent_category_slug = get_query_var('parent_category_name');

  $parent_category = get_category_by_slug($parent_category_slug);
  $category = get_category_by_slug($category_slug);

  if( !$parent_category && $category->parent != 0) {
    $wp_query->set_404();
    status_header( 404 );
    get_template_part( 404 );
    exit();    
  }
}

add_action('wp', 'load_404_page_for_subcategory_pages');

Add both of the hooks to the functions.php file and go to the settings page on the backend and save permalinks. It should work.