because I can't answer yet to this question: How to update product position (number) in specific category programmatically, because of my reputation. Hereby a new question about the updates for the position of a single category.

How would you only update products in that category with a curtain position, for example position 0. So only products with position 0 will change to the new number and products with position 10 will keep there position.

Hope someone can help.


1 Answer 1


You can use the same script from the response on the question you referenced and just add a condition.

$categoryId = 22; //replace with your category id
$newPosition = 100; //replace with your new position
$category = Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->load($categoryId);
$products = $category->getProductsPosition();
foreach ($products as $id=>$value){
    if ($value == 2) {//change position only if `$value` 2
        $products[$id] = $newPosition;
  • thanks for your reply and just tried a couple of things, but did not work yet. How would it look like if you would want to change only products with position 2? Thanks!
    – Coen
    Commented Feb 19, 2015 at 10:53
  • I edited the answer. you just need to modify the condition in the if statement. It's basic programming.
    – Marius
    Commented Feb 19, 2015 at 11:59
  • Thanks so much, you are great and works purfactly. I only placed 1 = sing instead of ==
    – Coen
    Commented Feb 19, 2015 at 12:10

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