Reply To: Age

#15653
Ernest Marcinko
Ernest Marcinko
Keymaster

Hi!

This is going to be a tough one, but I believe it’s sortable. The issue is, that the field is stored as a serialized object. That means, the values are not single strings or numbers, but complex objects converted (serialized) into a string to be stored in the database.

For example, this result, has the ‘ages’ custom field stored as:

Womens Short Course Quad a:11:{i:0;s:2:"12";i:1;s:2:"13";i:2;s:2:"14";i:3;s:2:"15";i:4;s:2:"16";i:5;s:5:"17-29";i:6;s:5:"30-39";i:7;s:5:"40-49";i:8;s:5:"50-57";i:9;s:5:"58-59";i:10;s:9:"60 and Up";}

This is a string version of an object, but the search within the database can only ‘see’ it as a simple string, and look for the selected values within it. As you can see there are the choosen values, but also some additional data about each field type and length. In this case, ’11’ can be found within this string, so choosing age ’11’ will match it, and give you as result.

After looking at some of these, I may have found a solution, so you don’t have to change this to a different structure. Notice that the age values always start with a double quotation mark. Luckily, the search does support it as custom field value. My solution would be to change the single numeric values on each line of the search radio fields to start with a double quote, thus making sure the match is actually on the value field. I mean changing this, to this:

Notice, that only values starting with “1” are preceeded with the double quote. It’s because 03, 04 etc.. are specific, and can’t be confused with the length values, as well as the other ones like “30-39”, which are unique enough.

This is a wild guess, but I’m almost positive that it will actually work. Let me know 🙂

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)