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.
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.
That didn't seem to work.
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:
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; }
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
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
Try this it may help you
print $sale_price and $boat_type you will get the custom attribute values
Thanks
Vijay