Skip to content

Instantly share code, notes, and snippets.

@spencejs
Created March 22, 2013 03:53
Show Gist options
  • Save spencejs/5218840 to your computer and use it in GitHub Desktop.
Save spencejs/5218840 to your computer and use it in GitHub Desktop.
Include Tags In Wordpress Search
@jfaMan
Copy link

jfaMan commented Aug 17, 2022

@Connum Thanks for the quick reply. I'm finding that even if I use your method, if I literally search just % signs like % or %%%, it will return strange posts that don't even exist, some with weird titles and excerpts with actual code in them. The same thing happens if I search with a blank input. Something like 100% will query fine though with your method or the original method.

I have it like this:

function custom_search_where($where){
        global $wpdb;
        $placeholder_string = $wpdb->placeholder_escape();
        if (is_search()) {
            $where .= "OR (t.name LIKE '".$placeholder_string.get_search_query().$placeholder_string."' AND {$wpdb->posts}.post_status = 'publish')";
        }
        return $where;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment