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.
<?php
$cat = get_cat_name( $wp_query->query_vars['cat'] );
$s = $wp_query->query_vars['s'];
echo $wp_query->found_posts . " results found with ' $s'";
if ( ! empty( $cat ) ) {
echo " in the '$cat' category";
}
?>Related Posts
Relevanssi Live Ajax Search
...accessibility. A basic search form looks something like this: <form role="search" method="get" class="search-form" action="/"> <label> <span class="screen-reader-text">Search for:</span> <input type="search" class="search-field" placeholder="Search …" name="s"> </label> <input type="submit" class="search-submit" value="Search"> </form> With Live Ajax Search, the form should look like this: <form role="search" method="get" class="search-form" action="/"> <label> <span class="screen-reader-text">Search for:</span> <input......type="search" class="search-field" placeholder="Search …" name="s" data-rlvlive="true" data-rlvparentel="#rlvlive" data-rlvconfig="default"> </label> <input type="submit" class="search-submit" value="Search"> <div id="rlvlive"></div> </form> Search results templates The Live Ajax Search plugin uses templates to display the search results. Using templates means it is easy to override the default search results from your theme if you want to......} ); Changes from SearchWP Live Ajax Search Relevanssi Live Ajax Search is a fork of SearchWP Live Ajax Search. I forked it from version 1.6.1 because it looked like SearchWP Live Ajax Search wasn’t getting updates anymore. I also wanted to improve the Relevanssi compatibility. Relevanssi Live Ajax Search...
Installing Relevanssi and adjusting the settings
...words to the search query and in OR search that works as expected, widening the search. In AND search, it will restrict the search, so it won’t work. Enabling this option will make Relevanssi index the synonyms as part of the post content, making them compatible with AND searches. Index......operator OR search will return all posts where at least one of the search terms appears. AND search will only return posts that have all search terms in them. OR search will prefer posts that have all search terms in them, so in most cases it is the better option.......all on all search forms on the site. If a search form includes the searchblogs parameter, it will override this setting. You still need to modify the search results template to get working permalinks, this (and the next) setting is just a shortcut for setting the searchblogs parameter. Search some...
Category filter for search results pages
Sometimes it's nice to have a category filter on the search results pages: a simple dropdown where you can choose the category you want to show. It's easy to create one using wp_dropdown_categories() ...
Filtering results by category
In order to filter search results by category, use the following code: $url = get_bloginfo('url'); $url = esc_attr(add_query_arg(array('cat' => '10', 's' => get_search_query()), $url)); echo "Fil...
Related Posts
...Relevanssi uses a simple CSS grid to lay out the related posts. This setting determines the minimum width of each element. Experiment with different values to see what works. If you want to style the related posts, Relevanssi wraps everything inside div#relevanssi_related, the header is in div.relevanssi_related_grid_header, and the grid......itself is in div#relevanssi_related_grid. Each post is a div.relevanssi_related_post. If you want to make more extensive modifications, you can create your template. Relevanssi will look for the relevanssi-related.php template inside the current theme templates directory, and if it finds one, it will use that instead of the default template. When......<li class="relevanssi_related_post"> <a href="<?php echo get_permalink( $related_post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"> <?php echo get_the_title( $related_post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </a> </li> <?php } ); ?> </ul> </div> <?php endif; Single post settings There are also Related posts controls on post edit pages. You can disable the auto-append for...
How to index parent categories
Suppose you have a parent category with no products in it but a child category does. If you search by the parent category can relevanssi be set up to show the products in the child category? Cars >...
Way late to the party, but just found this post and the above code worked great for me. Thanks!