Empty search input returns all posts

Just an alternative to the informative answer by @PieterGoosen. After Pieter posted this part: if ( ! empty( $q[‘s’] ) ) { $search = $this->parse_search( $q ); } it came to mind that it might be possible to re-parse the search query, within the posts_search filter, for empty search string. But the parse_search() method is … Read more

Display search results within the same page

The simplest option if you want to show search results within a page context you’ll need to do a custom loop, otherwise you won’t be able to access the page information. Change the input with the name s to something else like search or q to stop wordpress from doing it’s usual built in search. … Read more

Extend WordPress search to include user search

You can’t achieve this easily with WP’s built-in search system. Even if you managed to build a complicated query that pulls data from the user table, it would be incredibly slow. Search Unleashed had this functionality, but I’m not sure about compatibility with WP 3.2. I used it in the past as inspiration to add … Read more

How to look at code in WordPress repositories without downloading?

Good news and more good news! First – all of the code related to WordPress itself and its repositories resides in version control system (Subversion). Among other things that makes publicly available sites with all code in plain sight: http://core.svn.wordpress.org/ http://themes.svn.wordpress.org/ http://plugins.svn.wordpress.org/ One not so obvious result of that – if you can see it, … Read more

Limit search to latin characters

This solution filters search strings by applying a regular expression which only matches characters from the Common and Latin Unicode scripts. Matching Latin Characters with Regular Expressions I just had my mind blown over at Stack Overflow. As it turns out, regular expressions have a mechanism to match entire Unicode categories, including values to specify … Read more

Remove some pages from search

In WP_Query() there is a ‘post__not_in’ argument where you can exclude specific post ID’s. You would create a new WP_Query inside of your search.php and use the current $query_args, then add on your ‘post__not_in’. If you wanted to make it more dynamic, you could also build in some post meta where you could do a … Read more

How does WordPress search work behind the scenes?

EDIT – The current version of WordPress supports relevance, so this answer is no longer accurate. There’s no concept of rank or relevance, it’s just a simple LIKE query on the post title and content: ($wpdb->posts.post_title LIKE ‘{$n}{$term}{$n}’) OR ($wpdb->posts.post_content LIKE ‘{$n}{$term}{$n}’) You can use the posts_search filter to modify or completely replace the search … Read more

How to search for (partial match) display names of WordPress users?

Searching the main table Simply use WP_User_Query with a search argument. So if you want to search for example for a user with a keyword in his user_email or similar columns from the {$wpdb->prefix}users table, then you can do the following: $users = new WP_User_Query( array( ‘search’ => ‘*’.esc_attr( $your_search_string ).’*’, ‘search_columns’ => array( ‘user_login’, … Read more