searching for keyword phrases in quotation marks
-
Your function
uwpqsf_ajax
HTML escapes the keyword (esc_html($keyword)
). I am wondering why this is done since earlier it is run through thesanitize_text_field
WP function? The problem this causes arises when someone searches for a phrase enclosed by quote marks because those quotation marks get converted to"
. For example, say I search for"keyword phrase"
The actual search will be for two words:
"keyword
and
phrase"
which invariably ends up returning no results.
The WordPress native search already handles this well by recognizing such an entry as a phrase (and thus removing the quotation marks). Simply removing that
esc_html
part of your code would solve this problem. Unless there was a specific reason you included it that I am not considering?Now, for anyone that wants to change this, as I did, it can be done in your theme functions file using the following code:
add_action( 'pre_get_posts', 'allow_phrase_searches', 9999 ); function allow_phrase_searches( $query ) { if ( !is_admin() && $query->is_main_query() && $query->is_search ) { $query->set( 's', html_entity_decode($query->query_vars['s']) ); } }
https://www.ads-software.com/plugins/ultimate-wp-query-search-filter/
- The topic ‘searching for keyword phrases in quotation marks’ is closed to new replies.