after add new custom attribute, i am trying to get my custom attribute category, filter by the parent id, actually it return me a null value or empty array I used $category->getData('label_text')
, $category->getLabelText()
, $category->getCustomAttribute('label_text')
...
Do i have to join catalog_category_varchar and eav_attribute to reach it ? If someone of you have some advices.
thanks
1 Answer
Install/Upgrade
script:
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'my_custom_attribute',
[
// ...
'used_in_product_listing' => true, // for category pages
'visible_on_front' => true, // for frontend??
'is_used_in_grid' => true, // for category pages
'is_visible_in_grid' => true // for category pages
]
);
also on the collection do:
$collection->addAttributeToSelect('my_custom_attribute')
and then in the template you can just call:
$category->getMyCustomAttribute()
// or
$category->getData('my_custom_attribute');
If still not work run below command:
php bin/magento in:reindex
And more information this link ---
https://magento.stackexchange.com/a/184453/85907
Hope this help you
Thanks ...
$category
instance?