Include posts by matching authors in your search results

Out of the box, WordPress’ search isn’t that great. It only returns posts based on a LIKE query against the post title or post content. Often, you’ll want it to match against other data associated with your post, possibly including the author, tags, post meta fields, etc. These queries can get complex to perform on the fly, however.

The following code snippet allows you to include posts by matching authors in your search results. We’re modifying any search queries to also include all posts whose author display name or user login matches the query. You can change this to be the author’s first name, last name, or other fields.

Updated May 17, 2012: Improved the user search so we don’t query for all users and search with PHP; instead, search against the users table.

Show matching terms in your search results

WordPress’ internal search isn’t all that great out of the box, as I’ve discussed before. For instance, tags and categories aren’t included in the search query; as such, if your post is tagged “apple”, but there is no mention of “apple” in the title or post content, the post won’t be included in your search results.

One partial workaround is to search taxonomy terms against your query and include those in your results. I did this previously with the CUNY J-School’s tech website:

You can have something similar with the code snippet below.

[sourcecode lang=”php”]<?php
* Show matching terms for a given search query
* Best placed under the_search_form() in search.php
global $wp_query;
// Only show the matching terms on the first page of results
if ( $wp_query->query_vars[‘paged’] <= 1 ) {
$args = array(
‘search’ => get_search_query(),
‘orderby’ => ‘none’,
// You can change the first argument to an array of whatever taxonomies you want to search against
$matching_terms = get_terms( array( ‘post_tag’, ‘category’ ), $args );
if ( count( $matching_terms ) ) {
echo ‘<div class="all-matching-terms">Looking for? ‘;
$all_terms = ”;
foreach ( $matching_terms as $matching_term ) {
$all_terms .= ‘<a ‘;
if ( $matching_term->description )
$all_terms .= ‘title="’ . esc_attr( $matching_term->description ) . ‘" ‘;
$all_terms .= ‘href="’ . esc_url( get_term_link( $matching_term, $matching_term->taxonomy ) ) . ‘">’ . esc_html( $matching_term->name ) . ‘</a>, ‘;
echo rtrim( $all_terms, ‘, ‘ );
echo ‘</div>’;

Improvements in Tech website v0.4: Search query highlighting, suggested topics, and improved topical landing pages

Improvements in Tech website v0.4: Search query highlighting, suggested topics, and improved topical landing pages. The latest round of changes to our Documentation Redux theme. My favorite improvement is the search query highlighting with suggested topics at the top. Try out “final cut” or “wordpress“.

Iterating towards the ideal documentation theme for WordPress

A month or so ago, Joe and I started working on a dedicated documentation theme for the J-School’s Tech website. We’re calling it Documentation Redux, and it’s currently at v0.3. Closer to v1.0, we’d like to generalize it and make it available for others to use. For now, I want to review where it’s at and articulate where we’re trying to go. Continue reading “Iterating towards the ideal documentation theme for WordPress”


After a few months of punting, I finally configured Sphinx search on our dev box this afternoon. All in all, it took two hours to install, configure, and add to our tech WordPress theme. Here are my original notes if you want to try; if you install with a package manager, the greatest difficulty is understanding how to tune it and integrate into WordPress search. Next steps: refine search interface/experience, configure usage monitoring, add to corpus of data, rinse and repeat. Just think of how much more empowered educators would be if they had access to student search treads.

Researching better search functionality for the CUNY J-School network

Search is currently the dominant information retrieval paradigm, and WordPress’ internal search functionality is one step removed from atrocious. With that in mind, I’d like to significantly improve how search works on the J-School’s WordPress network. These are the notes I’m putting together as a part of my planning process.

A search for my name currently looks something like this:

Ideally, the search functionality should support these requirements:

  • Query across all of the content objects associated with the J-School’s primary website. These objects include posts, pages, events, blogs, databases, members, groups, and (coming soon) job opportunities. Eventually it would be nice to search attachments as well.
  • Expand a query to include content from any of the 216 and counting websites within the network. Filter results to a specific site, or by author, publication date, categories, or tags.
  • Highlight results based on matched keywords. If possible, show the sections of text matching the query.
  • Log queries and (optionally) provide analytics on search trends.

As far as I can tell, the options on the table are Sphinx, Solr, and search as a service from IndexTank. Sphinx appears the lowest-hanging fruit; Solr takes a couple of weeks to set up and configure, and IndexTank costs money for anything over 500 queries/day.

For Sphinx, there’s a WordPress plugin making it easier to integrate the two. The author has reasonably detailed documentation for installing Sphinx via the admin, if you chose to do that.

Another sys admin has written a three part series on extending WordPress search with Sphinx.

Extending search sources to custom fields is apparently as simple as adding to the select query.

The best way to dynamically add new blogs to the index for WordPress multisite is by editing the .conf file, although I’ll need to develop a way to add a unique index for every piece of content.

I intend to get Sphinx working on the development environment first, document the steps it took, then implement on production.