• I have a page setup to search a specific category. I do this by adding a “cat” request variable with the value being the category id. Without search reloaded (using lame search) it works; with search reloaded, it doesn’t. Can you advise on how to hack to make it work?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search Reloaded does not respect “cat” searches’ is closed to new replies.