Menu Close
    Hire us Request quote Reading list Switch to dark mode
    lockdownWebkulUp

    How to get all the options of a custom attribute in magento 2

    Today I will share with you that How you can get all the options of a custom attribute by the attribute code in Magento 2.

    First of all, you need to create an instance of EavConfig. I have shared the code that I used in a controller file, but you can use it in Helper or block according to your need.


    after that, write the function to get the all the options of the attribute,


    $arr now contains all the options as you can see below. The “value” is the option id and “label” is the frontend label of the option.

    . . .
    Subscribe Articles

    Just enter your email below to subscribe and receive weekly updates about the most interesting similar articles.

    You need to accept conditions to receive letters.
    You've Subscribed!

    Share article via

    . . .


    You can use this wherever you need to display options of a custom attribute. I have used this on Magento version 2.2.1 but this will work for other versions as well.

    For any queries, you can comment below.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close