Magento – Magento 2 : get custom attribute value display blank

catalogeav-attributesmagento2

In Magento2 , I need to get eav attribute value in category data. I used this below code. But, it's not working.

/** \Magento\Catalog\Model\CategoryFactory $categoryFactory**/
$category = $this->categoryFactory->create()->load(12); //12 is category id
$category->getData('attribute-code');

This attribute code value available in catalog_category_entity_varchar table.

M1 Array :

Array
(
    [entity_id] => 12
    [entity_type_id] => 3
    [attribute_set_id] => 3
    [parent_id] => 3
    [created_at] => 2014-04-29T00:25:55+02:00
    [updated_at] => 2017-09-20 11:40:47
    [path] => 1/2/3/12
    [position] => 2
    [level] => 3
    [children_count] => 0
    [request_path] => requestpath
    [is_active] => 1
    [name] => name
    [url_key] => url_key
    [is_anchor] => 0
    [meta_title] => 
    [display_mode] => PRODUCTS
    [custom_design] => 
    [page_layout] => one_column
    [url_path] => url
    [style] => 
    [faq_list_position] => 1
    [include_in_menu] => 1
    [landing_page] => 
    [custom_use_parent_settings] => 0
    [custom_apply_to_products] => 0
    [description] => 
    [meta_keywords] => meta
    [meta_description] => meta1
    [custom_layout_update] => 
    [available_sort_by] => Array
        (
            [0] => position
        )

    [custom_design_from] => 
    [custom_design_to] => 
    [filter_price_range] => 
)

M2 Array :

Array
(
    [entity_id] => 12
    [attribute_set_id] => 46
    [parent_id] => 3
    [created_at] => 2014-04-28 22:25:55
    [updated_at] => 2019-04-05 10:23:19
    [path] => 1/2/3/12
    [position] => 2
    [level] => 3
    [children_count] => 0
    [name] => name
    [url_key] => urlkey
    [image] => 
    [meta_title] => title
    [display_mode] => PRODUCTS
    [url_path] => urlpath
    [custom_design] => 
    [page_layout] => 1column
    [is_active] => 1
    [include_in_menu] => 1
    [landing_page] => 
    [is_anchor] => 0
    [custom_use_parent_settings] => 0
    [custom_apply_to_products] => 0
    [description] => 
    [meta_keywords] => meta
    [meta_description] => meta1
    [custom_layout_update] => 
    [available_sort_by] => Array
        (
            [0] => position
        )

    [custom_design_from] => 
    [custom_design_to] => 
)

How i get value ?

Please help me.

Thanks.

Best Answer

I think you should get data like this,

$category->getData('attribute_code');

 OR

$category->getAttributeCode();