Template Page Content Made Searchable

By default WordPress cannot search in template content. You should import your content into the data base. The plugin HTML Import 2 will help here. Another option is a separate search engine with a parser that can read the complete HTML output. The plugin Search Unleashed for example supports Apache Lucene. That’s probably too much … Read more

How to check if searchform.php is being included as widget?

Check if searchform is included? The get_search_form() function (that should be used) uses locate_template(‘searchform.php’); to display the search form. The later returns (as you can see from its source) the template filename if one is located So if you’re just wanting to catch the default way, then you should simply test ‘searchform.php’ === locate_template( ‘searchform.php’ … Read more

Search results sorted by post types

You can use filter posts_clauses For example: add_filter( ‘posts_clauses’, ‘post_query_order’, 20, 1 ); function post_query_order( $pieces ) { global $wpdb; $pieces[‘orderby’] = $wpdb->prefix.’posts.post_type ASC’; return $pieces; }

Filter taxonomy terms using multiple id in the edit-tags.php

It’s easy to implement. All you need is your own hook for get_terms_args filter: add_filter( ‘get_terms_args’, ‘wpse8170_get_terms_args’, 10, 2 ); function wpse8170_get_terms_args( $args, $taxonomies ) { if ( !in_array( ‘post_tag’, $taxonomies ) ) { return $args; } $matches = array(); if ( empty( $args[‘search’] ) || !preg_match( ‘/^\#(.*)$/’, $args[‘search’], $matches ) ) { return $args; … Read more

How to show a random selection of posts from the search

This is easy to do using the pre_get_posts action hook to set the orderby to rand in the query, something like this: function random_search_result( $q ) { if ( is_search() && is_main_query() ) $q->set( ‘orderby’, ‘rand’); } add_action( ‘pre_get_posts’, ‘random_search_result’ );

Extending wordpress search to include excerpts and taxonomies?

With WordPress 4.2.2 I’m using the following (admittedly fragile) method to search excerpts as well as the content and title without a plugin. This is the relevant snippet from functions.php. add_filter(‘posts_where’, ‘custom_posts_where’); function custom_posts_where($where) { if (is_search()) { $where = preg_replace( “/(\w+).post_title LIKE (‘%.*?%’)/”, “$1.post_title LIKE $2) OR ($1.post_excerpt LIKE $2”, $where); } return $where; … Read more