Jump to content

Selector for partial match for numbers


alxndre
 Share

Recommended Posts

Hi,

I'm trying to get partial match for fields of type integer, much like how %= and *= selectors works for string. Unfortunately these selectors are not working with numeric fields. Is it possible to do this?

For example, if I have pages with control numbers 14975, 91432, 33333, 32414, 13256

I'm looking for something like:

$pages->find("controlnumber%=14");

that would match 14975, 91432, and 32414, that would work for numeric fields.

Thanks. :)

Link to comment
Share on other sites

Hi Alxndre',
 

I suspect this will require a core change to support. The %= selector maps through to a MySQL LIKE statement - which is a string comparison operator.

Edit: Perhaps you could store a text field (let's say: controlnumber_string) which stores the string version of the value of the controlnumber field. You could make it hidden and have a hook populate it whenever controlnumber was changed. You could then use controlnumber_string in your selector.

  • Like 2
Link to comment
Share on other sites

Or perhaps another approach would be to use a standard SQL query to get an array of page IDs that match the desired controlnumber and then get the pages like this:

$pageIDs = array of pages_id results from SQL query of the field_controlnumber table

$matchingPages = $pages->getById($pageIDs);
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...