RE: the town, city, postcode search fields. The client

Hi,

RE: the town, city, postcode search fields.

The client I have built the site for has asked if I can code it so that the field is read left to right for example

If the postcode is N1 0JB, the results bring back NN13 and so on

What they would like is if the field read and recognised only data where the entered data started N1 to avoid lots of incorrect data being pulled back?

Is this possible?

Best

Paul

  • Modedaweb
    • WPMU DEV Initiate

    Hi Patrick,

    I apologise, I meant the custompress plugin used with the directory plugin as in the image attached.

    You can see the Postcode field it has the data GL1 1XH .

    Presently if I were to type in the front end search GL1 as a search, the data returns any data in the field that has GL1 such as SG L1 for example (if you want to test use N1 as a great example).

    So the client has asked if we can make the data be read as GL1 from the left so that G would have to be the first match in the search and L the second, rather than just finding the GL1 in any text in the field.

    Thanks

    Paul

  • Patrick
    • Support Monkey

    Hi again @jckmediauk

    Unfortunately, your screenshot didn’t post. But that’s Ok, because I found a link to the site in question in another of your threads. :slight_smile:

    I see what you mean now too. That would require redefining the regex used for the search function and the results it returns.

    I’ll see if I can find a member of the support staff who is more experienced with regex issues than I am. Hang on…

  • Modedaweb
    • WPMU DEV Initiate

    Hi Arnold,

    Thanks for the return and thanks Patrick also.

    What I need is for the search to return whatever you put in, so if N1 it will search N1 as the first set of letters in this search area and if you search GL then it will return GL as the first two letters of data in that field.. is this correct coding for that?

    Best

    Paul

  • Arnold
    • El Macho WP

    Are those the only two possibilities. Reject any thing that doesn’t start with GL OR N1? If that’s the case try

    ^(GL|N1).?

    Now you mention search. All the regex does in the custom fields is control what you can enter there. It has nothing to do with search. That’s a whole other kettle of fish.

  • Modedaweb
    • WPMU DEV Initiate

    Hi Arnold,

    The issue at hand is that in that particular field i need the search string to read left to right.

    Currently on http://www.opticianfinder.co.uk you can search for Town, City, Postcode.

    what currently happens is that when you enter N1 as part of a post code (N1 0EF) I need the data that is returned to start with N1

    .

    However if you test this, the string brings back data with N1 in the text such as NN1.

    I’d like the box to bring back all results starting with N1 or A3 or anything else being the start of that search string so to get NN1, you would need to serach NN1

    Does that clarify? Please let me know if it does.

    Thanks

    Paul

  • Arnold
    • El Macho WP

    You keep saying the search string reads from left to right. This is during creation of the search string? I thought we ere talking about custom fields?

    Regex applies to the input of the custom field value. It has nothing to do with how things will search. If you use the regex I gave above, you won’t be able to enter anything that doesn’t start with GL or N1 in the field that regex is applied to.

    If you are expecting a general search of posts to magically understand that it should only pick listings that have postal codes starting with GL instead of listings that have the name Glenn in it your not going to do it this way.

  • Modedaweb
    • WPMU DEV Initiate

    Hi Arnold,

    If you are expecting a general search of posts to magically understand that it should only pick listings that have postal codes starting with GL instead of listings that have the name Glenn in it your not going to do it this way.

    Do you have a solution as above?

    That’s what i was trying to get at

    Thanks

    Paul

  • Arnold
    • El Macho WP

    You would need to create a search form with fields for each of the fields oyu want to search on.

    Town ____

    Street ____

    Postal ____

    For example and then have code behind it the takes each field and crafts the search to hit those fields individually. Custom fields are all meta data filds in WP so you would use the search described here.

    http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    So custom programming.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.