Magento categories not showing on admin product edit screen
If you are failing to see your product categories while editing a product, but you can see the categories in your category edit menu, odds are your ‘children_count’ for categories isn’t correct on the database. A quick SQL statement fixes this:
UPDATE catalog_category_entity SET children_count = "1" WHERE children_count < 1;
If you are still having problems, it’s also possible that your level is set incorrectly. In my case setting level to the root category for all categories worked great.
foreach ($categories as $category) {
$category = $category->load($category->getId());
$level = $category->getLevel();
if($level > 2) {
$category->setLevel(2);
$category->save();
}
}