My theme is child of magento blank. On default magento 2 layered navigation sort labels of attribute in layered navigation by Count number of products that exist with this attribute.

I need to change this alphabetically sort order.

Example: Colours: Red (10) Blue (3) Yellow (2) Change to: Blue (3) Red (10) Yellow (2)

Where should I look? In module_layered_navigation? or Magento\Framework\Data\OptionSourceInterface? or somwhere else?

I found this in vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php

     * Create filter item object
 * @param   string $label
 * @param   mixed $value
 * @param   int $count
 * @return  \Magento\Catalog\Model\Layer\Filter\Item
protected function _createItem($label, $value, $count = 0)
    return $this->_filterItemFactory->create()

Maybe I could add somewhere usort:

usort($this, function($a, $b) {
if($a['order']==$b['order']) return 0;
return $a['order'] < $b['order']?1:-1;


  • it's code not working it please help me how to specific attribute option filter by alphabetically'
    – Rv Singh
    May 28, 2019 at 8:53

1 Answer 1


It looks like it works on the newest Magento 2.2.4

Sort order can be applied manually in the backend.

Edit attribute => Properties=> Sort using drag & drop

Easy way.

  • it's code not working it please help me how to specific attribute option filter by alphabetically use in programatically
    – Rv Singh
    May 28, 2019 at 8:53
  • Do you use any extra module for layered navigation? Remember to clean cache after changing sort.
    – BartZalas
    May 28, 2019 at 9:09
  • Actuall i have to use one module for layer navigation but in frontend side for brand attribute option left side not sorting alphabetically.so i need to show atoz
    – Rv Singh
    May 28, 2019 at 9:35
  • So this module is now enabled or not?
    – BartZalas
    May 28, 2019 at 9:48
  • Yes this module enable but my question is how to sort in left side brand section inside option label alphabetically order
    – Rv Singh
    May 28, 2019 at 9:54

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.