Skip to content

Magento2 page size not working on custom attribute

I have created custom product widget and it was working fine in 2.4.6 and I recently upgraded the version to 2.4.7-p3 and page size stopped working.

Working code without custom attribute release_date:

$collection->addAttributeToSelect('*');
$collection->addStoreFilter();                         
$collection->addAttributeToSort('release_date', 'desc');
$collection->setPageSize($this->getPageSize())->setCurPage($this->getRequest()->getParam($this->getData('page_var_name'), 1));

But when I adding a custom attribute filter release_date then page size is not working anymore:

$collection->addAttributeToSelect('*');
$collection->addStoreFilter(1);
$collection->addFieldToFilter('release_date', ['lt' => $todayDate->format('Y-m-d H:i:s')]);                 
$collection->addAttributeToSort('release_date', 'desc');
$collection->setPageSize($this->getPageSize())->setCurPage($this->getRequest()->getParam($this->getData('page_var_name'), 1));