Relevanssi includes a search form shortcode that can be used to display a search form. The shortcode is searchform and it was introduced in Relevanssi Premium 2.0 and Relevanssi 4.0.
will restrict the search form to just products.
will restrict the search form to categories 10, 14 and 17.
will do a multisite search on blogs 1, 2 and 3.
This function uses the WordPress default search form (provided by get_search_form()). However, if your theme includes a search form (in the searchform.php file), the function will use that. That may cause some unexpected results if your theme search form deviates from the WP standard a lot.
Add this code to your theme functions.php. Do note that this will then apply to all search forms, not just the ones generated by the shortcode. Versions 2.2.4 (Premium) and 4.1.3 (free) add a new filter hook relevanssi_search_form which does the same, but only applies to the shortcode search form.
If you copy and paste from the page, looks like extra spaces get included. Remove spaces from the end of all lines.
Hello, how can I make text Search disappears when you click on the container. I put value = Search but this does not go away when you click above must be deleted manually. Thx!!
how do you add the custom post type filter to this?
Just add hidden-type input field with the name "post_type" and value that matches the post type.
I have seen this tip at least 10 times now but for some reason it is not working. I am wondering if WP has changed something. For example if I test this on your site https://www.relevanssi.com/?s=download&post_type=page then I am still also getting "posts" in the search results. Any idea why?
Setting "post_type" to "page" has always been unreliable, WordPress silently changes the setting to "any". That has been the case for years. Instead of "post_type", use "post_types" to avoid the problem. https://www.relevanssi.com/?s=download&post_types=page works much better.
What I need is the site search form allow search by search: term + city + locality.
Nothing in the search form is necessary, just make Relevanssi index custom fields "locality" and "city", and searches will find posts by locality and city.
Sure you can do that; it's just a bit more complicated to do, and doesn't improve the use experience that much more.
You'd need to write some code that reads in the city and locality fields and creates a meta_query out of them and adds it to the search parameters.
I don't know, the placement of the search box is up to your theme. Relevanssi has nothing to do with it.
To get results from comments, enable comment indexing in Relevanssi settings and rebuild the index.
Is this what you use to put the actual search bar into your site? Where do you put this to put it in your theme and header? I'd be glad to pay if the search plugin came with a search bar.
I don't have a search window at all so not sure how to put this in to link to the newly set up Relevanssi.
Just wanted to say thanks– your search is working so much better than the default and what we've used before!
Thanks. My commenting system ate your other comments, but no, you don't need to use this shortcode or pay for anything, you can just use the default WordPress search widget that comes with WordPress.
Adjust the value to your liking.
Hi, please where I have to put this string (with different value)?
Sandro, put it where you want a search form to appear: in a post, for example.
Sandro, ah, I see – or actually don't, because you are trying to tell me something WordPress is removing from the comment. You can't adjust the length of the search form from the shortcode, you need to do it from CSS.
Is there a way to align the search button with the search field? So far, the search button is located below the field.
Jenn, the code doesn't do that; it's up to your theme. Modify the theme CSS to get the desired look for the field.
It appears that all search configuration options apply to sitewide searches. In other words, if I have a primary nav search intended to search the entire site, and I also want to add a search widget to a help / knowledge base page that searches only posts in a particular category, can I differentiate between the two? Is there a way to configure each search form differently to return different results?
where X is the number of the category.
Ok, thank you! But what if I want to restrict the results to 10 categories? Is it possible to do a check for an array of category values for the input type in a form?
Now I just need the indexing to complete. I only have around 300 posts and pages but it gets hung up around 30. I've let it sit for an hour but nothing happens. I reinstalled the plugin to see if that would fix the hang, but no. Do you know of any reason it would not complete the indexing process? I'm so excited to use this plugin but can't until I figure that out!
To sort the hanging indexing, try disabling shortcode extension in indexing settings. That probably solves the problem.
Thanks! The index hang has been solved with the shortcode extension disabling.
Still having problems with my form and restricting to specific categories, however. It is probably a simple solution but I'm just not seeing it. Upon running the search, I see the parameters in the search results URL with the search term and the category (trying with one, first) /?s=ads&cat=ads , but it also returns pages on my site that have no category (obviously because they are pages). Why does this happen?
Got it! Used the cat ID numbers instead. 🙂 Thanks!
If you want to use the category names, then the parameter is category_ name.
I'm using Relevanssi with bbPress, and would like to create a search form that searches only in specific Forums. As an example, we have several public-facing categories for users, then we have "Staff" forums that are all under a single category. I'd like to be able to have a search form that only searches forums/topics in the Staff section. Is this doable?
I have to disagree with your statement. Relevanssi makes bbPress so much better that I was planning to switch from bbPress to alternate stand-alone forums package and embed until I got Relevanssi setup. Once I added the code you've supplied in posts to work with bbP Private Groups and to merge topics and replies in search results, I'm a happy camper. You've done an excellent job, and I plan to go premium very soon.
That said, I've never run across the ability to assign a category to a forum, unless we're using different words for the same meanings. I assume you're talking about WordPress's built-in category system and not bbPress categories. If I'm wrong, and the shortcode you provided will limit search to bbPress parent categories, then I'll be an even happier camper.
Thank you for your work on Relevanssi, and your response.
So, I could use that shortcode to search all of, say, "Staff Forum 1" or "Public Forum 2", but not search for posts in "Staff Forums", if I'm thinking clearly. I suppose I could concatenate the forum IDs for post_parent.
Thought it definitely seems like a custom form to add the advanced search functionality is what I'll have to do rather than spend a lot of time setting up a bunch of different forms. Don't suppose you have any plans to implement such a feature in Relevanssi that would allow users to search on the frontend by selecting categories in a dropdown, by post date, or by author?
Anthony, if you list the post ID for "Staff forums" in the form, the search should include posts in both staff forums under it – listing a parent ID will include all children, including grandchildren.
This shortcode is as much of a form builder Relevanssi is going to get, I think, for now at least.
That resulted in once again receiving search results, but they are still not limited to the parents defined in the post_parent parameter of the shortcode.
My site does not contain a search for wordpress content at all. If I install relevanssi how do I create a search page? I tried just inserting the shortcode, but it doesn't create a form.
Fran, you can copy the default searchform.php from the Twenty Seventeen theme. That's a good start for the search form. As for the search results template, your theme probably has a Loop template you can use; if not, you can also look at the Twenty Seventeen for an example.
i added the search form shortcode to my site. i want to make the search form taller and longer. How would i do that?
Mark, you can use CSS to style the form any way you want.
I have attempted to remove my search.php template, but my search results are not filtering by category.
Lucas, I'm not sure why the "cats" parameter is not working, but if you change it to just "cat", looks like that works better.
I'm using ACF 4412. I have created a custom fields group called "AAA" with 8 custom fields inside (a1, … a8). I could not find any shortcode to search and filter the whole group nor the custom fields separatelly using Relevanssi 4011. I'd be much obliged if you could point me to the right documentation or to ofer me a soultion.
Claudiu, there's no simple shortcode solution for this, you have to build the meta_query structures yourself. See the WP Codex documentation for meta_query.
Matthew, yes, Relevanssi Premium can serch through all the sites in your multisite.
Can you change the text in the submit search button?
Yes. I've added instructions to the post.
Can I use the shortcode of search form to search Tags only?
Frank, if you're using Relevanssi Premium, [searchform post_types="post_tag"] will do a search form that only returns tag results.
how to find the short code to input in my header please?
Matt, the search form shortcode is [searchform], like described on the page. But in your site header, I would recommend just adding the search form in the template without a shortcode, it's cleaner and easier that way.