I am trying to get total number of results count in head.phtml page. I have used following code to get search term. But I am not sure how to get total number of results count here.

$term = Mage::helper('catalogsearch')->getQueryText();

Any help will be appreciated. Thanks,

3 Answers 3


Please try bellow code

 if($listBlock = $this->getLayout()->getBlock('search_result_list')) {
    $productCollection = $listBlock->getLoadedProductCollection();
    echo $productCollection->getSize();
  • Thanks, It is showing the product search count. Though, I noticed one thing, there is result discrepancy between to add this code or without this code.
    – Deecee2000
    Nov 9, 2015 at 19:50
  • e.g. I am trying to add the code at head.phtml file. If I don't add this code it is showing search results count 100, if I add it is showing 80
    – Deecee2000
    Nov 9, 2015 at 20:17
  • Thankks for this! I was able to use it to get the list of products outside the result.phtml :D
    – jehzlau
    Aug 12, 2017 at 17:22
  • @Deecee2000, how to get the same in magento2? Dec 12, 2018 at 10:24

I haven't been able to test this, but try something like this:

$size = Mage::helper('catalogSearch')->getQuery()->getSearchCollection()->getSize();
  • Thanks, but it is not working as expected. It is always showing same number (10152) on all the pages, even if you are non-catalogsearch page.
    – Deecee2000
    Nov 6, 2015 at 21:26

Old question, but I want to share the way I get it. More simple

echo Mage::getSingleton('catalogsearch/layer')->getProductCollection()->count();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.