---
title: "How to Get all Options of a Custom Attribute in Magento 2"
url: "https://dolphinwebsolution.com/how-to-get-all-options-of-a-custom-attribute-in-magento-2"
date: "2021-10-13T06:09:02+05:30"
modified: "2023-08-31T05:13:36+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 646
reading_time: "4 min read"
summary: "Magento 2 product attributes are generally the properties of the Magento 2 product that help customers choose between product variations and find the best suitable option. It could be color, size, ..."
description: "Today I will Share How To Get All Options Of a Custom Attribute in Magento 2. Magento 2 product attributes are generally the properties of the Magento 2 prod..."
keywords: "Get all Options of a Custom Attribute in Magento 2,Custom Attribute in Magento 2,Get all Options of a Custom Attribute,Get Options of a Custom Attribute,Options of a Custom Attribute in Magento 2, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Integrating Power BI into Your E-Commerce Strategy"
    url: "https://dolphinwebsolution.com/blog/integrating-power-bi-into-your-e-commerce-strategy/"
  - title: "Models, Resource Models and Collections in Magento 2"
    url: "https://dolphinwebsolution.com/models-resource-models-and-collections-in-magento-2"
  - title: "How to Add Placeholder Text in Field for Checkout in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-add-placeholder-text-in-field-for-checkout-in-magento-2"
---

# How to Get all Options of a Custom Attribute in Magento 2

_Published: October 13, 2021_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/Get-all-Options-of-Custom-Attribute-in-Magento-2-1024x536.png)

Magento 2 product attributes are generally the properties of the Magento 2 product that help customers choose between product variations and find the best suitable option. It could be color, size, weight, material, etc.

**To learn more about creating and managing product attributes, see:**

- [Product Attributes](https://experienceleague.adobe.com/docs/commerce-admin/catalog/product-attributes/product-attributes.html)
- [Attribute Sets](https://experienceleague.adobe.com/docs/commerce-admin/catalog/product-attributes/create/attribute-sets.html)

**There are two types of attributes used by Magento 2:**

- **Default or system attributes** are required for a store’s proper functioning and can never be deleted. In the Stores> Attributes> Product section, you can find default attributes (including name, price, URL, SKU, descriptions, images, etc.).
- **Custom attributes** are created by the store admin. You can add any number of attributes to this section.

**There are 2 ways to add new product attributes in Magento 2:**

- When working on a **specific product edit page**
- From the **Product Attributes page**

Under **Attribute properties**, describe basic information of the product attributes Magento 2.

- **Attribute code:** the unique identifier to manage the attribute: search, import/export, get attribute ID/name/value, etc.
- **Scope:** Decide how the attribute value is displayed and edited based on a specific level: *Global ⇒ Website ⇒ Store View*
- Global: The value of the attribute is shared by all websites and store views.
- Website: The value varies per website but stays the same for multiple store views under that website.
- Store View: Tailor different values per store view, primarily based on the languages.
- Set **Unique Value** to *Yes* to prevent duplication. Recommended for ID-number fields like SKU.
- **Attributes used for the configurable products must have Catalog Input Type to be drop-down and the Global scope.**

Following are **Catalog Input Types** to define the product attributes Magento 2.

- - ***Text Field:*** A single-line field to enter text
    - ***Text Area:*** A multiple-line field to enter text directly or using WYSIWYG Editor
    - ***Text Editor:*** Add WYSIWYG Editor to any custom field
    - ***Date:*** Date & Time can be picked from the calendar or typed directly into a field
    - ***Yes/No:*** A “switch” button between two pre-defined options: Yes or No
    - ***Dropdown:*** A drop-down list to choose one option at a time
    - ***Multiple Select:*** Used to create price fields. The currency used is determined in the system configuration
    - ***Media Image:*** A media image attribute becomes an additional image type, along with Base, Small, and Thumbnail
    - ***Fixed Product Tax:*** Used to define FPT rates based on the locale requirements
    - ***Visual Swatch:*** For [configurable products](https://dolphinwebsolution.com/shop/configurable-products-preselect-for-magento.html), the corresponding image is shown per swatch on visual option (e.g color)
    - ***Text Swatch:*** For configurable products, the corresponding image is shown per swatch on text option (e.g size)



### How To Get All Options Of a Custom Attribute in Magento 2

    Using the below codes can **Get All Options Of Attribute By Attribute Code** In Magento 2.

    ```
    <?php

    namespace Dolphin\Mymodule\Ui\Component\Form\Color;

    use Magento\Framework\Data\OptionSourceInterface;
    use \Magento\Eav\Model\Config;

    class Options implements OptionSourceInterface
    {
        /**
         * @var Config
         */
        protected $_eavConfig;

        /**
         * @param Config $eavConfig
         */
        public function __construct(
            Config           $eavConfig
        )
        {
            $this->_eavConfig = $eavConfig;
        }

        /**
         * {@inheritdoc}
         */
        public function toOptionArray()
        {
            $coloOptions = $this->getColorOption();
            return $coloOptions;
        }

        protected function getColorOption()
        {
            $attribute = $this->_eavConfig->getAttribute('catalog_product', 'color'); //color is product attribute.
            $options = $attribute->getSource()->getAllOptions();
            $optionsExists = array();
            /*foreach ($options as $option) {
                if ($option['value'] > 0) {
                    $optionsExists[] = $option['label'];
                }
            }*/
            return $options;
        }

    }
    ```


    - **$this->\_eavConfig->getAttribute:** This method have two parameter first is **entityType** and second is **attribute code.**
    - **Color** attribute from Catalog\_Product Eav Entity Types. Fetch all the options of the color attribute.

    **Checkout**: [**hire Magento 2 developer**](https://dolphinwebsolution.com/hire-magento-2-developers/)

    **Result:**

    ```
    Array
    (
        [0] => Array
            (
                [label] =>
                [value] =>
            )

        [1] => Array
            (
                [value] => 49
                [label] => Black
            )

        [2] => Array
            (
                [value] => 50
                [label] => Blue
            )

        [3] => Array
            (
                [value] => 51
                [label] => Brown
            )

        [4] => Array
            (
                [value] => 52
                [label] => Gray
            )

        [5] => Array
            (
                [value] => 53
                [label] => Green
            )

    )
    ```

    I Hope, This instruction will be helpful for you.

    If you have any difficulties regarding this blog, do consider them posting in the Comments section below!

    I’m here to help.

    **Thank you!**


---

_View the original post at: [https://dolphinwebsolution.com/how-to-get-all-options-of-a-custom-attribute-in-magento-2](https://dolphinwebsolution.com/how-to-get-all-options-of-a-custom-attribute-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:55:35 UTC_  
