I would like to know how to use the built in wordpress search to return results from all content on my site. Specifically, I want to search;
- posts
- pages
- tags
- custom post type (portfolio)
- custom taxonomy used in custom post type (skill, client)
- metaboxes used in custom post type (portfolio_caption, portfolio_excerpt, portfolio_credits, portfolio_links)
I would like one search form and don’t need to limit the search to certain post types or categories. Just enter the search term > click search > see matches from all content on my site. Simple 😉
Update: Preferably, I would achieve this through a function or custom database query rather than using a plugin. This is because I’m developing a theme and want this functionality included out of the box rather than requiring a user to download a plugin. (title changed)
DeluxeBlogTips.com 1) has an article on how to do combined searches in both posts and meta data. Basically, it involves two queries via the $wpdb object; one to search the meta table to get a list of
post_id
s and the other is a query of posts to getpost_id
s. You then merge the arrays and use that to do a query with aWP_Query
using theposts__in
argument.Using tags may be a bit tricky because 1. tags are meant to group posts together and 2. tags and taxonomies involve 3 different tables.
1) The linked article is not completely right. It should be
$keyword = "%".like_escape( $keyword )."%";
.Using the link @Wyck posted, check out http://wordpress.org/extend/plugins/search-everything/. Given the complexity of the task, a plugin really is your best bet to get ‘er done.
If you are truly opposed to a plugin, and know some SQL, you can do this with the $wpdb global variable.
For example, to query all posts that contain “sample_text” in the title, you would do something like:
Then you would do similar things for each of the other tables.