I have added positions to the products in category in the backend.

enter image description here

This position is working in Category page in Frontend. But this position of product is not working in Product list widget inside a CMS page.

enter image description here

How can this value of position be used in Product list widget?

This is value is stored in this table in magento2 database. enter image description here

  • If you product list widget then from which category you will pull the positions because one product could be assigned to multiple categories? Feb 12, 2020 at 13:05
  • Conditions If ALL of these conditions are TRUE : Category is 17 Feb 12, 2020 at 13:35

1 Answer 1


When I var_dump() my grid Product object, I found some data related to "cat_index_position" in it. This is actually the piece of data I had to use to sort my product list. enter image description here

enter image description here

So I run two for each loop to sort again my product array and I get my products positioned according to the value given to on Category settings in Magento admin.

$items          = $block->getProductCollection()->getItems();

$CatIndexPosition= array();
$positioned_items= array();
foreach ($items as $_item): 
endforeach ;
$zeroadjust = max(array_keys($CatIndexPosition))+1;
//echo $zeroadjust;exit;
foreach ($CatIndexPosition as $key => $value): 
endforeach ;

Now in our loop i replaced $items variable with $positioned_items which i have created.

<?php foreach ($positioned_items as $_item): ?>
    <div class="col-sm-6 <?php if($iterator==0){?>p-l<?php }?>">
        <div class="img-box">
  • nice answer but i have add code in 2.3.5 version and it is not working it any other change need? Jan 1, 2021 at 6:16
  • I have no idae about it, but you can check the code inside this file in magento 2.3 and then do adjustments. Jan 4, 2021 at 6:55

Your Answer

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

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