Return a list of Selected Option from a Select Attribute

Permalink 1 user found helpful
I'm building a custom block that returns images as well as information about them from some custom attributes. The basic text attributes are easy enough to get the values for, but getting the selected values from a select type attribute seems like a nightmare.

I've tried Jordan Lev's code from here:
$ak = CollectionAttributeKey::getByHandle('your_attribute_handle');
$satc = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
$values = $satc->getOptions();
foreach ($values as $v) {
    echo 'ID: ' . $v->ID;
    echo 'Value: ' . $v->value;

It throws a fatal error at this line:
$values = $satc->getOptions();

"Fatal Error: Call to a member function getAttributeKeyID() on a non-object"

I've checked my attribute handle and it is correct.

After looking through the Docs, I changed getOptions to getSelectedOptions, which gets rid of the error, but does not return any values. I've made sure there are selected option on the files and all, but getSelectedOptions still returns empty.

I'm running 5.5.2

View Replies:
A3020 replied on at Permalink Reply
I know it's an old post, but if someone stumbles upon this thread:

You should check if $ak returns an object.

//rest of code

If it doesn't return an object, double check if the handle and whether the attribute is an 'Collection' attribute.