One option is to make a plugin to help with the new functionality you need.
Any time you want to add new query variables to WordPress, you must declare them so they can be processed. (Or is ‘cat’ already a valid query variable? I forget.. if it is, you might want to call yours something else)
Example:
function my_query_vars ($vars) {
$vars[] = "cat";
return $vars;
}
add_filter('query_vars', 'my_query_vars');
Without that, you will not be able to read the data from $cat.
Now to read the data from the new variable, the method depends on the use_verbose_rule variable
if ($wp_rewrite->use_verbose_rules || !isset($wp_rewrite->use_verbose_rules)) {
the data must be referenced as $1
} else {
the data must be referenced as $matches[1]
}
That shows you how to get the first variable passed through the query, etc..
Now you just have to use the data to modify the search results.. which I have no idea about. I have not worked with the base search code 😉
i haven’t tried the Search Reloaded plugin but this sounds like it would be a good feature for that
the ability to have Radio buttons with Advanced Search conditions under your search bar would be really nice. Example,
SEARCH |_____________|
Search for:
Any Of The Terms
All Of The Terms
Click which categories:
Cat 1
Cat 2
Cat 3
Cat 4
Show posts by date:
All posts
Posts from 2005
Posts from 2004
Posts from 2003
@aleister: I can see the logic behind what you’re suggesting, but my PHP skills are limited to me fooling around with WP, and that just doesn’t cut it sometimes (like trying to create a plugin).
Personally I don’t think I’d be able to.
If someone who can write a plugin like this wants to, please, I’d be very grateful, but of course any other proposals to solve this would also be appreciated.
I may see about coming up with something when I make my next plugin. 🙂
OK mylagoon basically to add the categories to the end of the search term you need to add a hidden field with the values that you want added to the string. The script to use would be like this:
“
<form id=”searchform” method=”get” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
<input type=”text” name=”s” id=”s” size=”20″ value=”search in blog…” />
<input type=”hidden” name=”cat” value=”4,13,22″ />
</form>
“
It would be the last input tag that would do it for you
“<input type=”hidden” name=”cat” value=”4,13,22″ />”
Hope this helps.
th3rmite, thanks for your code–that was perfect!! It does exactly what I need it to. SWEET.
Great advice, this is exactly what I needed too. After installing the plug-in vCalendar, search wasn’t able to find anything anymore…
However, using comma’s to separate the cat id’s didn’t work for me. Workaround was repeating the hidden input fields:
<input type="hidden" name="cat" value="13" />
<input type="hidden" name="cat" value="8" />