{"id":1979,"date":"2022-03-02T11:14:54","date_gmt":"2022-03-02T11:14:54","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/programmatically-get-all-websites-in-magento-2\/"},"modified":"2025-05-22T09:16:10","modified_gmt":"2025-05-22T03:46:10","slug":"programmatically-get-all-websites-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/programmatically-get-all-websites-in-magento-2\/","title":{"rendered":"How to Programmatically Get All Websites in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento is a robust, scalable online platform used for selling online. Such an eCommerce platform supports the multi-website, multi-language and multi-store view. So, it is possible to build multiple websites, their stores and store view depending on the business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Are you a Magento 2 store admin handling multiple websites on the same platform?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When running an online store with multiple websites sometimes you may need to get the list of all the websites in Magento 2. Then, this solution will help you to&nbsp;<em><strong>programmatically get all websites in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method to Programmatically Get All Websites in Magento 2:&nbsp;<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The method to get the list of all the websites in Magento 2 is as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Magento\\Store\\Model\\ResourceModel\\Website\\CollectionFactory as WebsiteCollectionFactory;\n\nprotected $websiteCollectionFactory;\n\npublic function __construct(WebsiteCollectionFactory $websiteCollectionFactory)\n{\n$this->websiteCollectionFactory = $websiteCollectionFactory;\n}\n\n\/\/get website collection\n$websiteCollection = $this->websiteCollectionFactory->create();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share the solution with the Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento is a robust, scalable online platform used for selling online. Such an eCommerce platform supports the multi-website, multi-language and multi-store view. So, it is&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1979","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1979"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1979\/revisions"}],"predecessor-version":[{"id":14156,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1979\/revisions\/14156"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}