WordPress.org

Ready to get started?Download WordPress

Forums

Better Search
Highlighted search word all lowercase (5 posts)

  1. Annekee
    Member
    Posted 3 months ago #

    Hello Ajay & everybody,

    Is there a fix for turning all search words in lowercase? If visitors search for names I would like to keep the first letter a capital. The culprit is in (my) better-search.php:

    $sr = get_query_var('s');
    $keys = explode(" ",$sr);
    $excerpt = preg_replace('/('.implode('|', $keys) .')/iu', '<strong>'.$sr.'</strong>', $excerpt);

    Thanks in advance!

    https://wordpress.org/plugins/better-search/

  2. Ajay
    Member
    Plugin Author

    Posted 3 months ago #

    How about using something like

    $sr = strtolower( get_query_var('s') );
  3. Annekee
    Member
    Posted 3 months ago #

    Sorry for not being clear Ajay. I meant that the highlighted words in the search results are all in lowercase, e.g. "John Doe" turned into "john doe", but I want to keep the capitals. If there is a fix for that.

  4. Ajay
    Member
    Plugin Author

    Posted 3 months ago #

    I'm no expert on regex, but what if you omit the i in :
    /('.implode('|', $keys) .')/iu

    But, this might not completely solve your problem because the way I understand it, the search terms are very dependent on that of the user's search.

    Another option could be to capture the matches wherever there is a search term using preg_match_all and use those to highlight the words int he excerpt

  5. Annekee
    Member
    Posted 3 months ago #

    Regex is a nightmare to me... perhaps someone else can help?

Reply

You must log in to post.

About this Plugin

About this Topic