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

How do I remove Pages from search?

The below should make the page post type no longer search-able. function remove_pages_from_search() { global $wp_post_types; $wp_post_types[‘page’]->exclude_from_search = true; } add_action(‘init’, ‘remove_pages_from_search’);

How to highlight search terms without plugin

Add these 2 functions to your functions.php function search_excerpt_highlight() { $excerpt = get_the_excerpt(); $keys = implode(‘|’, explode(‘ ‘, get_search_query())); $excerpt = preg_replace(‘/(‘ . $keys .’)/iu’, ‘<strong class=”search-highlight”>\0</strong>’, $excerpt); echo ‘<p>’ . $excerpt . ‘</p>’; } function search_title_highlight() { $title = get_the_title(); $keys = implode(‘|’, explode(‘ ‘, get_search_query())); $title = preg_replace(‘/(‘ . $keys .’)/iu’, ‘<strong class=”search-highlight”>\0</strong>’, … Read more

How to create live autofill search?

The following uses jQuery UI Autocomplete, which has been included in WordPress since 3.3. (I’ve borrowed the format from @Rarst :D). It’s still not precisely what you’re after, but gives you a good starting point. The following uses a the basic jQuery UI styling, but you can use the one that’s currently worked out on … Read more

how to limit search to post titles?

Here’s a filter that’ll do the trick. Drop it into your theme’s functions.php or a plugin. /** * Search SQL filter for matching against post title only. * * @link http://wordpress.stackexchange.com/a/11826/1685 * * @param string $search * @param WP_Query $wp_query */ function wpse_11826_search_by_title( $search, $wp_query ) { if ( ! empty( $search ) && ! … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)