How to get Search result count and keyword in result.phtml in magento2.

I have overriden the Magento_CatalogSearch/templates/result.phtml file.

I need to show the count returned from the search result as well as the key searched here.

Is that possible to get it. Please anyone suggest on this.


  • Can you please upload your code ? Dec 12, 2018 at 10:34

3 Answers 3


You can get Search result count $block->getResultCount()

and use keyword for get $this->helper('Magento\CatalogSearch\Helper\Data')->getEscapedQueryText()

  • hi @Amit, got count but keyword is not returned Dec 12, 2018 at 10:39
  • My mistake, i don't paste proper class name
    – Amit Bera
    Dec 12, 2018 at 10:42
  • ok, thanks it worked, could you check the Terms and condition issue? Dec 12, 2018 at 10:48

To get Search Result count :

$resultCount = $block->getResultCount();

To get Search Keyword :

$helper = $this->helper('Magento\Search\Helper\Data');
$searchKeyword = $helper->getEscapedQueryText();

If you use Magento\CatalogSearch\Block\Result this block in your custom module. Then you can use this below code :

For search keyword :




For count :


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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