Thread Starter
Reuben
(@reuben)
I’m almost there on this one; I do:
$category_branch = “”;
$cat = get_query_var(‘cat’);
if (isset($cat) && !empty($cat)) {
// $category_branch = ” AND posts.ID = ANY (SELECT post_id FROM $wpdb->post2cat WHERE category_id=” . $cat . “) “;
}
and then just append $category_branch into the query.
However, I can’t get it working. What am I doing wrong?
Thread Starter
Reuben
(@reuben)
(BTW it’s commented out because it’s throwing an SQL syntax error)
Thread Starter
Reuben
(@reuben)
AHA. My host is using mysql 4, which doesn’t support subqueries. Here is the fix for the search_reloaded plugin:
Just before $search_query is defined, add the following:
$where = ” WHERE “;
$cat = get_query_var(‘cat’);
if (isset($cat) && !empty($cat)) {
$where = “, $wpdb->post2cat AS cat WHERE cat.category_id = ” . $cat . ” AND cat.post_id = posts.ID AND “;
}
Now, replace the line a little further down:
WHERE
with:
” . $where . “
This will only search one category. WordPress’ internal search has teh ability to search multiple, but I don’t need that, so …
Thanks for this thread, Rueben. Oddly, even the single category search using wordpress’ built in search function didn’t utilise the category passed it for me, so your solution was *very* welcome!
I’m attempting to take this a step further and have it accept multiple categories; if anyone can point me in the direction of someone who’s already done this, please post as I’m sure my solution won’t be pretty or quick! 🙂
Thanks, again.