Age

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15652
    occra
    occra
    Participant

    I thought the age thing was worked out, but it’s still giving me fits. It *almost* works but not quite.

    Age: Custom Field, Drop-down selection from list of ages and age ranges.

    One or more age is selected on the Custom Post.

    It all works exactly as expected unless you choose age 10 or age 11. If you choose one of those, then it will give you more results then you should have. It seems like it includes everything tagged with 12 and up. The extra ones showing up are definitely not set with 11 or younger as an age selection in the custom field.

    The search setting for that custom age field is STRING OPERATOR – LIKE. For fun I tried all the others and they yielded no results at all.

    Sorry to bug you about this, but this was the most important part of the search and if it only works partially then it kills the trustworthiness of the filters in the eyes of the end user altogether.

    I’m willing to change to a different kind of field setup, but I’ve tried several and this is the closest I’ve gotten.

    #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 :)


    #15659
    occra
    occra
    Participant

    Boom! That works perfectly and I learned a little bit in the process. The results are exactly as expected now for the Age filter. Thanks again!

    #15663
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.