Continue reading Search results breakdown by type

Search results breakdown by type

Do you want to have a breakdown of search results by post type? This could be used for example to show a list of post types like books, movies, or albums on a review site, and make them links to limit the search results to that post type. This is fairly easy to do with…

Read more Search results breakdown by type 51 Comments on Search results breakdown by type
Continue reading Category title in the search results page

Category title in the search results page

If you’re using category restriction dropdown on your search form, here’s a bit of code that you can add to your search results template to show how many hits were found and what the category is. If no category was selected, this’ll just show how many hits were found.

Read more Category title in the search results page 1 Comment on Category title in the search results page
Continue reading Filter search results by date

Filter search results by date

You can specify date limits on searches with by_date search parameter. Here’s a link you can add to your search results page to offer your visitor the ability to restrict the search results to last day: <?php echo ‘<p><a href=”‘ . get_bloginfo(‘url’) . ‘?s=’ . get_search_query() . ‘&by_date=1d”>results from the last day</a></p>’; ?> The date range is…

Read more Filter search results by date 11 Comments on Filter search results by date
Continue reading Sorting search results

Sorting search results

If you want something else than the default relevancy ranking, you can use orderby and order parameters for the search query. Orderby accepts $post variable attributes and order can be asc (ascending) or desc (descending). The most relevant attributes here are most likely post_date and comment_count. If you want to give your users the ability…

Read more Sorting search results 36 Comments on Sorting search results
Continue reading Showing the number of search results

Showing the number of search results

If you want to show the number of search results found on the search results template, you can find the value in the variable $wp_query->found_posts. Just add <?php echo ‘<p>Found ‘ . $wp_query->found_posts . ‘ hits.</p>’; ?> in your search results template. In case that produces no results, try introducing the global $wp_query variable like…

Read more Showing the number of search results 4 Comments on Showing the number of search results