Question: Does anyone know why in some stores the save does not change the is\_anchor and in some stores it does? It is not working on a multi-store site (multiple default root categories)., though there may be other reasons. 

The code below generally works. When it does not it, the save has no effect, without any log errors.

$anchorNew has the correct value in it.

```
Mage::app()->setCurrentStore($store_id);

$categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('entity_id', array("gt" => 1))
    ->setOrder('entity_id') ;

foreach($categories as $category) {
    $anchor = $category->getIsAnchor();
    if ($anchor == 1 ) {
        continue;
    }
    $category->setIsAnchor(1);
    $category->save(); 

    $anchorNew = $category->getIsAnchor(); // this shows a 1 in is_anchor
}

```

I checked the database and there are not as many entries in - `catalog_category_entity_int` 
 WHERE attribute\_id = 51 - as there are categories. The $category->getIsAnchor() returns null for many of my categories.

Answer: 
Almost certainly the reason is that you have ***Use Flat Catalog Category*** set to ***Yes*** and your code doesn't account for this scenario. 

Try turning that setting off in ***System -> Configuration -> Catalog -> Frontend*** and then run the script again. When you switch flat catalog back on again, be sure to reindex the required tables.
• Create a php file, Add below content

```
<?php 
error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once('app/Mage.php');

Mage::app();

$categories = Mage::getModel('catalog/category')
 ->getCollection()
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('is_anchor', 0)
 ->addAttributeToFilter('entity_id', array("gt" => 1))
 ->setOrder('entity_id')
 ;

foreach($categories as $category) {

 $category->setIsAnchor(1);
 $category->save();
}

echo “Done”;
?>

```

* Upload to root of Magento server.
* Access the file from your web browser.