I am currently working on a project where it loads a collection of products with a CategoryFilter.

$category = $this->categoryFactory->create()->load($categoryId);
    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);

    return $collection;

From administration panel (Catalog -> Categories), you can choose "manual sorting" or "automatic sorting" from "Display Settings".

But this option seems to not work.

Can someone explain me, what I am suppose to load the collection with admin filters ?

Thanks you.

1 Answer 1


The setting provides at the administration panel will work at frontend when you go to a Category page and magento already build the code according.

If you will want to apply the administration section sorting to your custom collection then you have to write the code.

If you sort field is product attribute then you can use addAttributeToSort('{Attribute_Code}', '{SortOrder}');. This function need to add with your collection.

Suppose, you want to sort by name attribute Ascending order then use add below code before return $collection

 $collection->addAttributeToSort('name', 'asc');
 return $collection;

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.