filterByAttribute

Permalink
Hi,

I have a a page list using this code

$pl->filterByAttribute('hp_price', $frPrice, '<=');


but hp_price is a string and $frPrice is a number

Is there a way I can set the hp_price as a number also?

TMDesigns
 
JohntheFish replied on at Permalink Reply
JohntheFish
If the problem arises from a select attribute where it is stored as a number, but mapped to a label, then you can use filterBySelectAttribute().

( EDIT - I probably got that back to front. You wanted numbers, not strings. )
TMDesigns replied on at Permalink Reply
TMDesigns
Thank for that but I don't think it will work.

I am passing the $frPrice in a dropdown from a form. This code is sat in the controller and I am trying to sayonly show pages if the attribute is less or equal to the number in frPrice. The problem is that price is a text field attribute not a number.
hutman replied on at Permalink Reply
hutman
I don't think there is a good way to make this happen. There is a Number Attribute Type, but in order to use that you would have to create a new attribute and delete the old one then set it on each page again.

Otherwise you could just get the full page list and test for that attribute value in the loop when you are displaying them.
TMDesigns replied on at Permalink Reply
TMDesigns
Hmmm, this was what I was thinking, but I can do that as the this then mucks up the pagination as you are returning say 20 items but only showing 5.

Also the number value acts like a select box so I would have to put in up to 8000 entries to get $8000 to show as some prices are $7891

Not great
JohntheFish replied on at Permalink Reply
JohntheFish
How big is the un-filtered list? If not enormous, you could get the whole lot, filter in php, then paginate afterwards.
TMDesigns replied on at Permalink Reply
TMDesigns
There is currently around 300 entries max

How could I do the pagination afterwards?