---
title: "How to Get All Regions/States of Specific Country by Country Code in Magento 2?"
url: "https://magecomp.com/blog/get-all-regions-states-of-specific-country-by-country-code-magento-2/"
date: "2022-10-07T14:43:50+00:00"
modified: "2025-05-27T12:10:57+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 315
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Get the list of All Regions/States into array of a Specific Country by Country Code in Magento 2. Learn how"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Create Customer Programmatically in Magento 2?"
    url: "https://magecomp.com/blog/create-customer-programmatically-magento-2/"
  - title: "How to add a Custom tab in Admin Sales Order view Magento 2?"
    url: "https://magecomp.com/blog/add-custom-tab-admin-sales-order-view-magento-2/"
  - title: "Top Magento Development Companies in UK"
    url: "https://magecomp.com/blog/top-magento-development-companies-uk/"
---

# How to Get All Regions/States of Specific Country by Country Code in Magento 2?

_Published: October 7, 2022_  
_Author: Dhiren Vasoya_  

![How to Get All Regions States of Specific Country by Country Code in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/10/How-to-Get-All-Regions-States-of-Specific-Country-by-Country-Code-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

This Magento tutorial will help you Get All Regions/States of Specific Country by Country Code in Magento 2.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-2.webp)](https://magecomp.com/services/hire-magento-programmer/)

In your Magento 2 store, many regions and states are added to a specific country. You can easily [**add a new Region to a specific Country**](https://magecomp.com/blog/magento-2-add-new-region-for-specific-country/) when required. When you go on adding new regions, you do not remember which region a particular country holds. For that, you need to have a list of all regions/states assigned to a specific country in Magento 2.
You can use the below method to get the array of all the regions/states of a specific country in Magento 2.
## Steps to Get All Regions/States of Specific Country by Country Code in Magento 2:
**Step 1:** We are getting data in the root script. So go to the below path
**magento_root_directory\pub\getRegions.php**

And add the code as follows
```
<?php

use MagentoFrameworkAppInterface;

try
{
    require __DIR__ . '/../app/bootstrap.php';
}
catch (Exception $e)
{
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}
try
{
    $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);

    $objectManager = $bootstrap->getObjectManager();

    $appState = $objectManager->get('MagentoFrameworkAppState');
    $appState->setAreaCode('frontend');
    $countryModel = $objectManager->get('MagentoDirectoryModelCountry');
    $countryCode = 'IN';
    $regionData = $countryModel->loadByCode($countryCode)->getRegions()->loadData()->toArray();

    echo "";
    print_r($regionData);

}
catch(Exception $e)
{
    print_r($e->getMessage());
}
```

## [![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2023/04/Magento-Malware-Removal-CTA-1.webp)](https://magecomp.com/magento-malware-removal.html)

## Conclusion:
This way, you can fetch the list of all regions/states of a specific country by country code in Magento 2. You can also integrate [**Magento 2 City and Region Manager Extension**](https://magecomp.com/magento-2-city-and-region-dropdown-manager.html) to manage states, regions, and zip codes easily.
If you face difficulty getting all regions/states of a specific country by country code in Magento 2. Share the tutorial with your friends and stay updated with us so that you do not miss out on any important solution.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/get-all-regions-states-of-specific-country-by-country-code-magento-2/](https://magecomp.com/blog/get-all-regions-states-of-specific-country-by-country-code-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-08 07:40:53 UTC_  
