I have created a custom category attribute title_description and is showing on the admin side and I can save data. But when I try to show the value on the frontend using getTitleDescription() it is not showing anything. It is working for default category attributes like getName() and getId(). In my block I have created the function
public function getCurrentCategory()
{
$currentCategory = $this->registry->registry('current_category');
return $currentCategory;
}
And in .phtml file I am calling
$block->getCurrentCategory()->getTitleDescription()
It works on other pages where I am using a collection of categories and looping through it. But not working when calling an individual category
You can add your custom attribute to Magento's list of attributes that it'll load by default when loading categories.
Create a file called
catalog_attributes.xmlin theetcfolder of your module.Note that the group is called
catalog_category, which is the group for auto-loaded attributes. This file is capable of doing other things as well, which you can learn about here.