0

I'm using a Magento 2.4 and in my project I have many static pages that I would like to be part of my search results.

Magento 2 search

How could I add Magento 2 static pages in my search results?

1 Answer 1

0

Use the below code in search template:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$queryText = $objectManager->create('Magento\Search\Model\QueryFactory')->get()->getQueryText();
$pageCollection=$objectManager->create('Magento\Cms\Model\Page')
->getCollection()
->addFieldToFilter('is_active',1)
->addFieldToFilter(
  array('title','content'),
  array(array('like'=>'%'.$queryText.'%'), 
  array('like'=>'%'.$queryText.'%')));

Your Answer

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

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