• Resolved gregseitz

    (@gregseitz)


    Hi – apologies if this has been posted before, I have searched high-and-low…

    This might seem redundant, but I need to extend WordPress’s search capabilities so users can search on the category name. If I have a category named “x” but the term doesn’t appear in any post, I’d like my users to be able to search for “x” and get the category page or at least posts in that category in their search results.

    Hope I’ve made myself clear and thanks in advance for any help!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hey, how about a new plugin?!

    Search Category Name
    Download plugin | View source

    To install, download search-catname.php, upload the file to your wp-content/plugins/ directory, and activate Search Category Name under Plugins.

    This will work with standard search, except you need to pass a new query var along with the ‘s’ (search) one; the new var is ‘type,’ and you want to pass a value of ‘cat’ for it. You can set up a search form to do this in many ways, but simplest may be to add a ‘hidden’ input that defines the var name and value:

    <input type="hidden" name="type" value="cat" />

    The search result url would then look something like:

    /?s=foo&type=cat

    Note: It may be possible to pass the whole thing off to the correct category query instead of a search result of posts from the category, but then I’d need to spend more time on it than I did on this plugin. ;)

    Thread Starter gregseitz

    (@gregseitz)

    Wow. I thought I couldn’t be more in love with WP and the WP community. You sir are awesome. Thank you.

    I hate to be the guy who could even be perceived as looking a gift horse in the mouth, but upon installation it looks like using this plugin, users will only search category name. I was just hoping to include category names in all searches.

    Would it be possible to include two hidden inputs that instruct search to search both?

    Anyway, thanks so much.

    I was just hoping to include category names in all searches.

    Hmm. Ok, I’ve brushed this horse’s teeth (R1.0.1, same links above).

    Look in the plugin file near the top for:

    //>> user-configurable variable
    define('SZUB_INCLUDE_CAT_SEARCH', 0);
    //<< user-configurable variable

    Change the defined value of SZUB_INCLUDE_CAT_SEARCH to 1:

    define('SZUB_INCLUDE_CAT_SEARCH', 1);

    so the plugin will cause regular old WordPress searches to include category names. Note that using ‘&type=cat’ will continue to force searches to work on category names *only* (in case you want that).

    Thread Starter gregseitz

    (@gregseitz)

    Works like a charm. Thanks so much.

    grintoul

    (@grintoul)

    Hi Kafkaesqi,

    Great plugin! Got a bug report for you though. If the user searched for anything containing an apostrophe (‘) it returns the following error. Any suggestions?

    Thanks for the great plugin,
    Guy

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘%’ AND post_type = ‘post’ AND post_status = ‘publish’ ORDER BY post_date DESC ‘ at line 1]
    SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.* FROM wp_posts LEFT JOIN wp_post2cat ON ID = post_id LEFT JOIN wp_categories ON cat_ID = category_id WHERE 1=1 AND (((post_title LIKE ‘%%’) OR (post_content LIKE ‘%%’))) AND (post_type = ‘post’ AND (post_status = ‘publish’ OR post_status = ‘private’)) OR cat_name LIKE ‘%’%’ AND post_type = ‘post’ AND post_status = ‘publish’ ORDER BY post_date DESC LIMIT 0, 20

    I got the same error message.

    I’m also getting the same error. From what I understand, this plugin doesn’t work with new versions of MySQL. Here’s why:

    Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3.

    Info here: https://dev.mysql.com/doc/refman/5.0/en/join.html
    Anyone know how to get in touch with the plugin author to see if this can be easily fixed?

    How could you make it so your categories are shown in a drop down box to add to the search parameters.

    For example… I have “cities” as categories.

    So, I want a drop down box that lists them all… Dallas, St. Louis, New York, LA, etc…

    Then I want people to be able to select “Dallas”, or “LA”, or whatever and search only in that category.

    Also, leaving it as “All Cities” (or the default) would search all the categories.

    Any ideas on how to do this?
    I think this little plug-in is close… but not sure.

    Never mind, found it. ??

    My question is addressed in this post…
    https://www.ads-software.com/support/topic/62266?replies=16#post-366116

    Thanks all!

    In case anyone comes looking, I’ve just now updated Search Category Name to support WordPress 2.3 (sorry, I honestly forgot about this plugin).

    As for the issue abv brings up, what I know of it is that the problem should not arise when the comma operator is not in use. In any case, I’ve tested on both MySQL 4 and 5 platforms.

    anyway to fix the comma problem?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Search category names’ is closed to new replies.