{"id":217,"date":"2018-10-24T11:47:17","date_gmt":"2018-10-24T11:47:17","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/10\/24\/get-page-wise-products-collection-in-magento\/"},"modified":"2025-05-22T17:15:47","modified_gmt":"2025-05-22T11:45:47","slug":"get-page-wise-products-collection-in-magento","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-page-wise-products-collection-in-magento\/","title":{"rendered":"How to Get Page Wise Products Collection in Magento"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you own a Magento online store, it is important that you design the store and its navigational features that make it easy for visitors to find the products they want and shop easily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you offer a large number of products, it is not possible to display all of them at once. Also, loading all products at once takes time which results in script time-out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution to the problem is load products on scroll or display page wise products collection. Here I\u2019ll give the solution to&nbsp;<i><strong>get page wise products collection in Magento.<\/strong><\/i><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example to Get Page wise Products Collection in Magento:<\/h2>\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=\"\">$p = 0;\n    while (1) {\n        $p++;\n        $products = Mage::getModel('catalog\/product')\n            ->getCollection()\n            ->addAttributeToSelect('*')\n            ->setPageSize(200)\n            ->setCurPage($p)\n            ->setOrder('id', 'ASC')\n            ->addAttributeToFilter('status', array('eq' => '1'));\n            \n            foreach ($products as $_product) {\n                echo '&lt;br>'.$_product->getId();\n            }\n            \n            if ($p >= $products->getLastPageNumber()) {\n                break;\n            }\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When fetching product collections page-wise in Magento, managing the number of items displayed per page is important. You can achieve that using the <a href=\"https:\/\/meetanshi.com\/blog\/how-to-use-setpagesize-in-magento-2-collections\/\"><code>setPageSize<\/code> method in Magento 2 collections<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hopefully, the above example helps you to get the solution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you own a Magento online store, it is important that you design the store and its navigational features that make it easy for visitors&#8230;<\/p>\n","protected":false},"author":5,"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-217","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/217","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":15572,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions\/15572"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}