Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › No results for "M&M", but results for "M&"
- This topic has 6 replies, 2 voices, and was last updated 6 years, 8 months ago by
Ernest Marcinko.
-
AuthorPosts
-
September 27, 2019 at 6:52 pm #24143
tomclayson92
ParticipantOne 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 #24149tomclayson92
ParticipantThis 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 #24157Ernest Marcinko
KeymasterHi,
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.
October 1, 2019 at 6:12 am #24168tomclayson92
ParticipantThanks 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 #24171Ernest Marcinko
KeymasterAt the moment, I am seeing results like so: https://i.imgur.com/TX3ta4k.png
Was there any change anywhere?October 2, 2019 at 6:04 am #24179tomclayson92
ParticipantWith the same query, I don’t get any results. I didn’t change anything to do with the search yesterday.
October 2, 2019 at 11:50 am #24186Ernest Marcinko
KeymasterHi,
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:
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; } -
AuthorPosts
- You must be logged in to reply to this topic.