I am using Magento 2.3
I have Created one custom attribute "Popular Category" for categories. Now I am trying to get the value of this attribute in front end but I am not getting it.
I have tried this using below code:
<?php
$cid = 3131;
$c = $objectManager->create('Magento\Catalog\Model\Category')->load($cid);
echo $c->getResource()->getAttribute('popular_category')->getFrontend()->getValue($c);
?>
But I am not getting any values at all.Please check my logic for custom attribute in below file.
app/code/Myvendor/CategoryAttributes/Setup/InstallData.php
<?php
namespace Rootways\CategoryAttributes\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Category::ENTITY,
'popular_category',
[
'type' => 'int',
'label' => 'Popular Category',
'input' => 'select',
'required' => false,
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'visible_on_front' => true,
]
);
}
}
?>
I want to display images of those categories in which popular category is set to YES. So How can achieve this?