Support » Plugin: Relevanssi - A Better Search » Partial Word – Text and Number value (postcodes)

  • Resolved jamestc989

    (@jamestc989)


    Hello,

    I am trying to create a postcode search facility which works with a full postcode and a partial postcode.

    My post titles are all the beginning half of a postcode eg: GU51

    Someone searching could either search: “GU51” or “GU513ED” or “GU51 3ED”

    I have set the search to partial words and also added the functions for inside word matching, but it only works if there is the space between the first half and last half. If there’s no space “GU513ED”, there is no result.

    Please help 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    It just doesn’t work that way. You can always match a shorter search term to a longer word, but not the other way around, because Relevanssi isn’t allowed to skip letters in the search term.

    But the solution is fortunately fairly simple: you just need to add the space there. Check the search term: if it looks like a postcode without a space, add the space.

    However, if those are UK postcodes, figuring out what looks like a postcode is not an easy task – there’s a rather wild variety of possibilities there.

    But once you figure out how to recognise a postcode, you can do the adjustment with a filter:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_postcode_check' );
    function rlv_postcode_check( $query ) {
        if ( $query->query_vars['s'] is a post code ) {
            $query->query_vars['s'] = the post code with the space
        }
        return $query;
    }
    Thread Starter jamestc989

    (@jamestc989)

    Hi Mikko,

    Thanks a lot for the reply! I have passed it on to one of my team to take a look at and try and crack it following your suggestion 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Partial Word – Text and Number value (postcodes)’ is closed to new replies.