How to get Category Collection per Storewise in Magento 2?

When we have multi-store setup and store have different category assigned at that time we need to get store wise category collection.
We can get store wise category collection by below code snippet.

1. Use directly Objectmanager is not best/Recommended way to do in Magento, use Block with the construct() and fetch method in your phtml file.

2. Recommended Way Using Create Block file and call from the template,

Create Block PHP file,

Display second level category, all those categories which have Level equals 2. call below function from a template file,

For getting all categories of current store call below function in template file,

You can change the custom argument by passing argument on above function from template file.

One Reply to “How to get Category Collection per Storewise in Magento 2?”

Leave a Reply

Your email address will not be published. Required fields are marked *