+1: I would love the same thing 🙂
I’m looking for the exact same thing!
Well, this almost works with Relevanssi. The problem is with the exclusion, because if you set exclude_from_search
and indexing to “all public types”, you can’t later include.
So, this’ll take some fixing. However, I have a fairly simple solution: support for negative post types.
You could then do this in the first search:
<input type="hidden" name="post_type" value="-foo" />
and this in the second search:
<input type="hidden" name="post_type" value="foo" />
And it would work the way you want.
I’m going to work on Relevanssi a bit today and tomorrow, probably resulting in a new version in couple of days, and I’ll include this.
Looks like WordPress won’t let me do that. I’ll have to come up with another solution.
I decided to take the easy way out: just replicate WordPress behaviour. What you tried will work with Relevanssi starting from the next version (2.6, probably).
Just committed version 2.6, so once that’s available, try to see if your original method works.
msaari, this works perfectly! Thank you so much!
To anyone else, reading the thread later, just to save you some time, here’s how I got it working…
In the WordPress Admin, go to Settings >> Relevanssi, and under “Restrict search to these categories and tags:” I entered the category numbers for all the categories I wanted the main search to index.
Then I edited my theme, and added a second search field, with a unique “name” and “id” and added this line of code within the form…
<input type='hidden' name='cat' value='14' />
So now the main search field searches every category, except for 14, and the second search field only searches category 14 – which is exactly what I was looking for!
Once again, thank you msaari. It’s very cool to express a desire for a certain feature, and then have a solution in less than a day! You rock!
I’m glad I could help you.
@masaari, I thought it was ok, but I´m afraid it´s not…
1) I need to restrict the general search to don´t find anything in a especific post type. So, I put the exclude_from_search
at this post type arguments…
2) At the Relevanssi Admin I choose to index ‘All public post types’ so it excludes my especific post type. Now, the general search is all right.
3) I want my second search to find posts just in that especific post type, so I add the code <input type="hidden" name="post_type" value="that_custom_post_type" />
But it doesn´t find anything. I think the ‘All public post types’ is limiting this search too…
I´m using the version 2.6.
Yes, change “All public post types” to “Everything”. That way everything will be indexed, and the exclude from search should restrict the general search as you wish.
@msaari If I define it to “Everything” the general search can find my “exclude_from_search” post type…
Index everything and check the “Respect exclude_from_search for custom post types:” checkbox.
Now is perfect! I didn´t see this checkbox before.
Thanks again @msaari