List all values for a custom attribute

Permalink 3 users found helpful
I've been searching through all the docs and forums and I can't seem to solve this.

Basically, I have a custom page attribute select list called "body_parts" which can be multi-selected. I want to be able to display a list of all the possible values that are available. Ideally, I'd like to be able to filter out values that aren't being used on any page (but that's in my wildest dreams).

Anyone know how to do this?

Thanks.

snebold
 
SVijay replied on at Permalink Reply
SVijay
Hi,

Try this it may help you

global $c;
$sale_price = $c->getAttribute('sale_price');
$boat_type = $c->getAttribute('boat_type');


print $sale_price and $boat_type you will get the custom attribute values

Thanks
Vijay
snebold replied on at Permalink Reply
snebold
That didn't seem to work.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
snebold replied on at Permalink Reply
snebold
Actually I had seen this thread before but for some reason didn't implement it correctly, but this time it did work for me, thanks!

The code that worked is reproduced here:
Loader::model('attribute/type');
Loader::model('attribute/categories/collection');
$ak = CollectionAttributeKey::getByHandle('your_attribute_handle');
$satc = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
$satc->setAttributeKey($ak);
$values = $satc->getOptions();
foreach ($values as $v) {
    echo 'ID: ' . $v->ID;
    echo 'Value: ' . $v->value;
}
tallacman replied on at Permalink Reply
tallacman
Im totally out of my league here but I just read this in Remos new book

<?php
$attr = $c->getAttribute('background');
echo '<xmp>';
print_r($attr);
echo '</xmp>';
?>


Excuse the interruption if this makes no sense in this context.

Steve
jordanlev replied on at Permalink Reply
jordanlev
Hi Steve,
No, that doesn't apply to this situation. Your code retrieves the value that was entered for an attribute. What the OP is looking for is all of the "possible choices" that an attribute could be (which only really makes sense with the "select list" attribute type).

For example, let's say your attribute is "background color", and you make the choices "red", "green", "blue", "yellow" available (so when someone adds a new page they can choose from those 4 options in a list). Someone goes to add a page and chooses "green".

Your code would tell you "green", but the OP's code would tell you "red, green, blue, yellow".

Hope that makes sense.

-Jordan