Get Website ID from Website Name
Websites are already loaded on startup, so there is no need for additional queries. You can and should use:
$websites = Mage::app()->getWebsites();
to receive them. Then to look up by name:
foreach ($websites as $id => $website) {
if ($website->getName() === $name) {
return $id;
}
}
You need debug the collection by ->getSelect()->__toString()
for checking it give right value or not.
$siteModelCollection = Mage::getResourceModel( 'core/website_collection' )->addFieldToFilter( 'name', $site );
// print the Query
echo $Query = $siteModelCollection ->getSelect()->__toString();
echo $siteId =$siteModelCollection->getFirstItem()->getId();
Update:
Use load():
for this case you need to call load()
function of resource model
of core/website
for getting proper collection
Now you can get id of first store by using below code:
$siteModelCollection = Mage::getResourceModel('core/website_collection')->addFieldToFilter( 'name', $site)->load();
echo $Query = $siteModelCollection ->getSelect()->__toString();
echo $siteId =$siteModelCollection->getFirstItem()->getId();