Search by Category allows your visitor to select which category they want to search your blog inside of. This allows visitors to find the exact article they're looking for and helps increase viewer loyalty.
Where to Download
How to use
- Download and install the plugin
- Configure the options inside the settings menu
- Edit your Theme file to include this code where ever you want the search form:
<?php if(function_exists('sbc')){
sbc();
} else { ?>
...your standard form code here...
<?php } ?>
or if you want to use it in a post or page:
[sbc]
Customizations
List of arguments in order
- focus - replaces "In all categories"
- hide_empty - 1 means true, 0 means false
- search_text - replaces "Search for..."
- only_cat - category name/slug/ID [removes dropdown list]
- excluded_cats - must be category IDs seperated by commas (ex: 1,2,3) / removes categories from dropdown list
- exclude_child - 1 means true, 0 means false
- inall_exclude - must be category IDs seperated by commas (ex: 1,2,3) / removes categories from "in all categories" and dropdown list
If you don't want to customize a setting, use: null, 0, or ''.

So cool. This is a good feature. Thank you very much.
I think this will really help my readers find things. I use a three column format and the text in the categories box is a bit too long (Categorie is all I can get to show). Is there a way to change that font size? I figure it is pulling it from my template but I thought there might be an over ride I can do by modifying the code of the plugin?
@Duane: Im sorry to say that SBC was just not meant to be pushed into that small of an area. Even with lowering the font size to it's smallest readable level, the whole word wasn't visible in Firefox and IE.
I suggest copying this CSS into your stylesheet and disable the SBC setting in WP-Admin:
form#sbc-search {clear: both; display: block;}
form#sbc-search * {margin: 0px; display: block;}
form#sbc-search input#s {background: #f5f5f5; border: 1px solid #bbbbbb; padding: 4px 10px; width: 80%; margin: 0px auto 10px;}
form#sbc-search select#cat {background: #fbfbfb url(arrow.png) 88% 50% no-repeat; height: 30px; width: 99%; border: 1px solid #bbbbbb; padding: 4px 20px; -khtml-appearance: none; /* fix default safai styling */ border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px;}
form#sbc-search select#cat option {padding: 2px 4px;}
form#sbc-search input#sbc-submit {height: 30px; width: 40%; margin-top: 10px; border: 1px solid #bbbbbb; float: right; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px;}
Thanks Fire G for taking the time to respond. I tried this but couldn't find the place the disable SBC setting (although if you meant to uncheck the box 'Use the SBC Form styling', I did that). So the problem persisted. In the process of working in the CSS stylesheet I noticed my sidebar 2 was set at 170px wide, while sidebar one was set at 175px. So, I changed the sidebar 2 width voila, it worked. Now the whole word 'Categories' is visible as well as the little down arrow. That also made the elements at the right side of my page line up better. Thanks!
The link to download is wrong. "http" has two "h" ;)
Great post… good suggestions…thanks!
Hi,
I have just downloaded and installed your plugin and I think it's a great one.
I just noticed a bug that I thought would be nice to tell you about.
I installed the plugin into a page and when I search for something it displays the correct results.
However, when there is no result to show it displays" No results found. Try another search"
And below that I get the regular search form and not the Search by Category form!
Is there a way to prevent that from happening?
thanks,
Thanks for the kind words.
what you'll need to do is look in your theme's index.php for the search box that you mentioned and just replace that code with the SBC code. You should also do the same with all of your other theme files.
I think could be nice the ability to select more than one single category...
Don't you?
Is there search by tags option?
@GadgetGuru: No since the drop-down would be Gigantic and the default WordPress search already searches based on category (but orders it based on publish date. There's a plugin to change that already).
Hi,
Currently I have this plugin displaying on only certain category archives. I'd like to make is so that the default search is to search the current category, and another option is to search all categories.
Can you suggest a way to do this?
Thanks!
@John, That's actually a great feature I could add in. When the next release goes live (will be soon) you'll be able to do it then.
thank's a lot for your work, it's the plu ing i search... so is there any way to hide category list ? (i use a template page and i don't want the user can search other thing than only one category) ... thank's for your respond
Using WP 2.8.3 and when I use the shortcode on a page the search form forces itself to the top of the page above where I want it to display. Any idea how I can make it show up where I want it?
Also, does this plugin search post/page content, tags, comments... or just titles?
Thanks!
Also, just noticed a couple other bugs.
One, I cannot disable any categories. I click the checkbox and choose save and then the checkbox is blank again. Any ideas?
Two, Disabling the style doesn't seem to change anything.
Once again I'm using 2.8.3 with the default wordpress theme.
Thanks,
If I can get these bugs ironed out it will be perfect!!!
Now this if I try to exclude categories and click save:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/mylocald/public_html/wp-content/plugins/search-by-category/search-by-category.php on line 107
Great plugin! Its works fine on the front end.
The backend is displaying the same error Paul stated above. It saves the categories to exclude but it cant be altered.
Is there any fix for this?
Thanks.
Thanks guys, i'll look into it.
Your latest update fixed the error and now it will allow me to select categories to exclude from the dropdown. One more question though, how can I make this plugin include tags in its search?
Thanks, awesome plugin by the way!
Wordpress search is already configured to search based on tags. All this plugin does is remove results that aren't in the selected category.
Glad you enjoy the plugin.
I created a post and added a tag (my zip code) to it. Then I searched for that zip code and nothing showed up. Is there a setting in wordpress that I don't know about that needs to be set?
Also the [sbc] tag still forces the search form to the to of my post...any ideas how I can make it show up half way down the post where I would like to have it?
Thanks again!
Hi! Thanks for this plugin. i am using it and it's working fine but I'm searching how to replace the drop-down menu by a list of categories (selection using radio buttons). Anyone who can help on adding this feature? Can we simply modify something in the plugins code? Thanks for your help. Laurent.
Great plugin! and thanks for this.
but replace the drop-down by check boxes is good.
Is there a way to allow searching of the text used in the Blogroll (Linklist) and Link Categories? Another plugin perhaps or maybe this can be altered?
thanks for your plugin !
please, how to configure this for search only in title ?
@Jeremy: You can use the "Search Everything" plugin to customize search results.
@Fire G: Thanks, but the "Search Eveything" plugin do not allow to search only in title or i did not found this options...
Hi there,
Would it be possible to have some settings on this plugin where i can search under a parent category(pg) for its child categories(cg).
i.e> Price (pg) to show 1,000-5,000(cg) and 5,000-10,000(cg)
and another one to show something else
i.e> Year (pg) to show 1990-2000(cg) and 2000-2010(cg)
showing at the same time?
In conclusion, making settings to customize the drop down menu's with specific pg and cg's giving [sbc1], [sbc2]...etc
@Eddie: Neat Idea, I may put it in the next version. But currently, no, there's no way of doing that.
Would you consider a handsome paypal donation for a working beta version within a week or two? I cant find anything else that does this, and i sure aint sure how to code it, but i gotta deadline in 3 weeks.
@Eddie: Shoot me an email to 'fireg@fire-studios.com' with your proposition and a clearer explanation of what you want.
Is it possible to generate a link to search inside a specific category?
I want to search for a specific tag inside a specific category, and then list the results.
Example
LINK_TO_CLICK_ON -> Search results with all posts tagged with "audi" inside the "cars" category.
Of course I can create all those pages manually with the wp_query_posts() function, but this would take up months to do it for all possible combinations :)
I just want to use search.php or archive.php etc.
Hello
I am very new beginner and tryed to install this plugin. But I dont know where in theme to make this change
1.
4. ...your standard form code here...
5.
Can you explane for me more where I should paste this in theme file?
I tryed but that was feil.
Thanks in advance
I see that here http://net.tutsplus.com/articles/news/building-a-custom-search-by-category-wordpress-plugin-new-plus-tutorial/ i think you just rip that.
@Luis: I wrote that article.
i dont understand where i put the code ?
01.
04. ...your standard form code here...
05.
@dany: Just replace "...your standard form code here..." with the search form code you used before SBC so that if you delete or deactivate the plugin, your site doesn't lose its search box.
First of all, thank you for creating such a great plugin. I've been searching and searching for something like this for quite some time.
I just had a quick question.. is it possible to remove certain categories from being searched from within the 'In All Categories' selection?
I like how you can manually exclude categories from the drop-down, however, those categories are still searched when a visitor selects 'in all categories'...
@Dennis: That's a good idea. I'll push it in a new release.
@Fire G
Thanks for acknowledging my post! I'll keep my eyes open for the next release.
You can see how it functions on my site here: http://www.redcanary.ca
Hello,
Sorry I'm not much of a coder and can't seem to figure out where to paste the code:
1.
4. ...your standard form code here...
5.
Which CSS file do I install this code in? I tried SearchForm.php and it didn't work, just made # symbols next to all of my search boxes. Also, is it possible to only display the Search by Category options on certain pages or categories?
Thanks!
Mike
@Fire G - was wondering if you might be able to help? I'm running into a small issue when I get my search results page. Any thoughts?
For some reason, when I do a search, I am getting the appropriate posts back but I am getting 4 blank small-posts added to the bottom.
I have my site turned off at this time, but here is the code that is popping up when I inspect it with Firebug. (This is one instance, but it repeats 4 times).
Here is the code I'm using:
Anyone have any ideas? Thanks in advance.
Mark
@Mark: Your code seems to have gotten filtered so I'm unable to help. You can use services like http://pastebin.com to handle the code.
Okay, so no obviously not - sorry, I posted the embed code from pastebin.com, but it looks like it removed it again. Let's try this way.
Firebug code for search results:
http://pastebin.com/embed_js.php?i=jJdMKSgp
Code for the search bar itself:
http://pastebin.com/embed_js.php?i=nCRVZrUj
Hopefully this works....
Thanks,
Mark
@Mark: The problem looks to be in your index.php file. There are several HTML errors, but I'm unable to fully identify the problem since I can't view the source or see the erroneous page.
Great plugin!
do you know how to modify the search so it searches through tags?
Currently it seems to use the default wordpress search options which is title and description
Help appreciated
Hey, the plugin is fantastic!
Is it possible to search within certain categories but on different pages.
For example if I have a search bar on the "news" page I want to only searches stuff in the "news" category....and the search box on the "competitions" page I only want to search the "competitions" category. Does this make sense?
Is there anyway to limit the categories searched on the actual insert code?
@Martin Gibson: Currently no, the plugin has that functionality, but only on category pages (ie: if you're in the "news" category it auto-selects "news"). I the next update (2.0) that customization will be added.
Hi, when I search in a specific category the plugin shows also posts from other categories.
I only put the shortcode in a page. Is that enough for the plugin to work correctly?
Is there a way to remove the drop down menu option? I only want the ability to search one category on a particular page, so the drop down isn't necessary.
Hi,
I was struggling with the plugin to get it work in my template so I posted a comment here.
In the meanwhile I found the solution and want to share it with you:
http://www.deluxeblogtips.com/2010/05/search-by-category-wordpress.html
I am looking forward to the 2.0 release!
Is there a solution to prevent the plugin to show pages when 'all categories' are selected in the search? I want the search to show only posts as output.
Hi,
I upgraded to 2.0 and used the shortcode on a page. Now I get some text 'bam:' before the search box. I looked in the php-file but cannot find any code who could be related to this piece of text. How can I remove this piece of text?
@Jan: Sorry! It was part of my debug section I forgot to remove!
Okay I updated the plugin and bam-bam is gone now ;)
Thanks for your support!
@ Fire - I use a plugin to order the categories. In the dropdown the categories are still alphabetical. Is there an easy solution to change the code in the search-by-category.php to get the same ordering?
Hello Fire G
I like your advanced search. I installed it and use it on a page [sbc]
Three Questions
1.
I type in the keyword to search and choose the category. If I dont click very very fast on the search button automatically the category page opens with all posts from category without any search result.
If I click very fast on the search button I got the search results. It works very fine. but I am sure that my visitors dont click so fast. and so they will get only the list of the posts in one catagory.
how I can stop the automatically mecanism. so that we have to click active on the search button to get the result. not automatically.
2.
Are there any new entries in the database ? How I can delete it after deinstall your plugin ?
3.
I want to put the submit (Search Field) under the category field. all in position "center"
I wrote but the Search Field is only walking down on the right side ?
Thanks
Roland
@Jan: No, right now there is no functionality, but I may include it in 2.1. You can change the parameter "name" on line 235 to another column name (ex: ID, name, etc...) if you want to order it that way.
@Rolandoo: I can't reproduce your error from #1 if you could link me to your site I may be able to investigate. #2: Yes, there is 1 field added to the wp_options table "sbc-settings", you can delete it using any database management tool (such as phpMyAdmin or the like). #3: Look at the default CSS markup to see how to style it and also how many selectors you need to override the ones in the sbc-stylesheet.
Thank you
the error is that every time if the user choose the category automatically the script is going to the choosed category and is not waiting for clicking search. IE, Mozilla, Opera all the same.
Other installed code I will analyse. Roland
@ Fire: Okay I will look into that ... thanks again.
Whenever I hover over the "search" box, it switches the font to bold and expands whole thing. How can I make it so that it is just bold all the time? (or just not bold). Thanks.
Nevermind, found a fix.
Hi Fire G,
I am having the same problem as Roland. I type a search term, choose a category and, before I have time to submit the search, I get the chosen category page. With no search term filtering.
You will find it doing this on this site: http://www.philatelicdatabase.com/
Any solution to this would be much appreciated and make this excellent plugin perfect.
@Richard: The problem is with your categories drop-down widget in your sidebar. Both drop-downs have the value of "cat" for their name thus the javascript added by the widget is affecting the search drop-down as well. If you change that value in the widget from "cat" to anything else the search and other drop-down will work without a hitch.
@Roland: You're probably in the same boat as Richard.
Thanks Fire G!
All sorted. I am now using a different plugin for the categories drop down (Extended Categories - in case anyone's interested) and it has fixed the problem. Thanks again for a great plugin and your super quick reply.
- Richard
Hey love the plugin but how did u remove the 3d borders in IE on the dropdown list???
Hello.
Can I add NextGEN gallery option (or WP-Calendar records, for example) to dropdown categories list?