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.
How could I add Magento 2 static pages in my search results?
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.'%')));