Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › No results for "M&M", but results for "M&"
This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko 3 years, 8 months ago.
- AuthorPosts
- September 27, 2019 at 6:52 pm #24143
One of the main product we expect to be selling is M&M’s (the chocolate candy). When users search for this however, no results appear. If I search for just “M&”, then it works correctly. Why might this be?
September 28, 2019 at 12:16 pm #24149This appears to be happening due to WPML’s treatment of the ‘&’ character. Searching for M&M works correctly, but obviously no user will know that. I have had similar issues with WPML before, and they haven’t been helpful, so is there any way to convert characters like & into ‘&’ before searching if a translated language is being used?
September 30, 2019 at 9:47 am #24157Hi,
Sure, I think we can do something about this. The issue seems to be indeed the ‘&’ character storage as HTML entity. There is this knowledge base article, that allows replacement of some characters with others. In your case the code will be:
This should hopefully do the trick.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 1, 2019 at 6:12 am #24168Thanks for the snippet, but that hasn’t quite seemed to work. It is replacing the character, but still no search results, and now the original ‘M&’ search, which was working, has also stopped working.
October 1, 2019 at 1:11 pm #24171At the moment, I am seeing results like so: https://i.imgur.com/TX3ta4k.png
Best,
Was there any change anywhere?
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 2, 2019 at 6:04 am #24179With the same query, I don’t get any results. I didn’t change anything to do with the search yesterday.
Attachments:
You must be logged in to view attached files.October 2, 2019 at 11:50 am #24186Hi,
I see the issue now, it is not the ‘&’ character, but the apostrophe.
Searching for:
M&M’s
..returns results, but searching:
M&M's
..does not. It’s a different apostrophe character. Assuming that every apostrophe is stored like that, I would suggest this custom code then:
Best,add_filter('asp_search_phrase_before_cleaning', 'asp_replace_characters', 10, 1); add_filter('asp_query_args', 'asp_replace_characters', 10, 1); function asp_replace_characters( $s ) { $characters = "'"; // Type characters one after another $replace_with = "’"; // Replace them with this (space by default) if ( is_array($s) ) { if ( isset($s['s']) && !$s['_ajax_search'] ) $s['s'] = str_replace(str_split($characters), $replace_with, $s['s']); } else { $s = str_replace(str_split($characters), $replace_with, $s); } return $s; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.