title: Magento: Can't get categories children
body: <p>For some reason this code is returning NULL when trying to get a categories subcategories.</p>
  
  <pre><code> &lt;?php var_dump($_category-&gt;getChildrenCategories()); ?&gt;
  </code></pre>
  
  <p>Here is the full code from a .phmtl file.</p>
  
  <pre><code>&lt;ul id="nav_vert"&gt;
              &lt;?php foreach ($this-&gt;getStoreCategories() as $_category): ?&gt;
              &lt;?php if ($_category-&gt;getIsActive()) { ?&gt;
              &lt;?php $open = $this-&gt;isCategoryActive($_category); ?&gt;
              &lt;?php $potential = $_category-&gt;hasChildren(); ?&gt;
              &lt;li&gt;&lt;a href="&lt;?php echo $this-&gt;getCategoryUrl($_category); ?&gt;"&lt;?php if($open) { echo ' class="open"'; } ?&gt;&lt;?php if($potential) { echo ' class="potential"'; } ?&gt; &gt;&lt;?php if($potential&amp;&amp;$open) { echo 'v '; } elseif($potential) { echo '&gt; '; }else{ echo '  '; }?&gt;&lt;?php echo $_category-&gt;getName();?&gt;&lt;/a&gt;
                  &lt;?php if ($open &amp;&amp; $potential): ?&gt;
                  &lt;?php var_dump($_category-&gt;getChildrenCategories()); ?&gt;
                  &lt;ul&gt;
                      &lt;?php foreach ($_category-&gt;getChildrenCategories() as $subcategory): ?&gt;
                      &lt;?php $subCat = Mage::getModel('catalog/category')-&gt;load($subcategory); ?&gt;
                      &lt;?php $open = $this-&gt;isCategoryActive($subCat); ?&gt;
                      &lt;?php $potential = $subCat-&gt;hasChildren(); ?&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo $this-&gt;getCategoryUrl($subCat); ?&gt;"&lt;?php if($open) { echo ' class="subopen"'; } ?&gt;&lt;?php if($potential) { echo ' class="potential"'; } ?&gt;&lt;?php if(!$potential&amp;&amp;$open) { echo ' class="final"'; } ?&gt; &gt;&lt;?php if($potential&amp;&amp;$open) { echo ':: '; } elseif($potential) { echo '&gt; '; }?&gt;&lt;?php echo $subCat-&gt;getName(); ?&gt; (&lt;?php echo $subCat-&gt;getProductCount(); ?&gt;)&lt;/a&gt;
                          &lt;?php if ($open &amp;&amp; $potential): ?&gt;
                          &lt;ul&gt;
                              &lt;?php foreach ($subcategory-&gt;getChildrenCategories() as $subsubcategory): ?&gt;
                              &lt;?php $subsubCat = Mage::getModel('catalog/category')-&gt;load($subsubcategory); ?&gt;
                              &lt;?php $open = $this-&gt;isCategoryActive($subsubCat) ?&gt;
                              &lt;li&gt;&lt;a href="&lt;?php echo $this-&gt;getCategoryUrl($subsubCat); ?&gt;" &lt;?php if($open) { echo ' class="final"'; } ?&gt;&gt;&lt;?php echo $subsubCat-&gt;getName(); ?&gt; (&lt;?php echo $subsubCat-&gt;getProductCount(); ?&gt;)&lt;/a&gt;&lt;/li&gt;
                              &lt;?php endforeach; ?&gt;
                          &lt;/ul&gt;
                          &lt;?php endif; ?&gt;
                      &lt;/li&gt;
                      &lt;?php endforeach; ?&gt;
                  &lt;/ul&gt;
                  &lt;?php endif; ?&gt;
              &lt;/li&gt;
              &lt;?php } ?&gt;
              &lt;?php endforeach ?&gt;
          &lt;/ul&gt;
  </code></pre>
  
  <p>This line always returns true </p>
  
  <pre><code>&lt;?php $potential = $_category-&gt;hasChildren(); ?&gt;
  </code></pre>
  
  <p>And I know that the category has children.</p>
  
  <p>Can anyone suggest why this doesn't work?</p>
  
  <p>This is how I place the phtml in the page:</p>
  
  <pre><code>&lt;reference name="left"&gt;
      &lt;block type="catalog/navigation" name="catalog.vertnav" template="catalog/navigation/vert_nav.phtml" before="-" /&gt;
  &lt;/reference&gt;
  </code></pre>
  
  <p>Magento version 1.5.1.0</p>