<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Garage &#187; category</title>
	<atom:link href="http://wpgarage.com/tag/category/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpgarage.com</link>
	<description>wordpress tricks, hacks, and tips</description>
	<lastBuildDate>Tue, 15 May 2012 11:49:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Hack the WordPress Search Function: Search Categories and Child Categories</title>
		<link>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/</link>
		<comments>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 06:23:56 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[WordPress as CMS]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[child category]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[parent category]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[subcategory]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/</guid>
		<description><![CDATA[<p>Recently, we had a client who wanted a special recipe search. There were 2 ways to extend the search functionality &#8211; manually or dynamically. 1. Search One or More Categories Manually If we want to search one category, we could have used this solution which lets you manually add category numbers to the search function: [...]</p><p>This post was originally published at <a href="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/">How to Hack the WordPress Search Function: Search Categories and Child Categories</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/" data-url="http://illum.in/r4sFhK" data-text="How to Hack the WordPress Search Function: Search Categories and Child Categories" data-count="vertical" data-via="wpgarage" data-related="wpgarage"><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/&amp;layout=box_count&amp;show_faces=true&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/"></g:plusone></div></div><p>Recently, we had a client who wanted a special recipe search. There were 2 ways to extend the search functionality &#8211; manually or dynamically.</p>
<p><strong>1. Search One or More Categories Manually<br />
</strong></p>
<p>If we want to search <strong>one category</strong>, we could have used this <a href="http://www.sandboxdev.com/blog/wordpress/123/search-specific-category-in-wordpress/">solution</a> which lets you manually add category numbers to the search function:</p>
<p>[Replace value="5" with your category number.]</p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;searchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221;&lt;?php echo wp_specialchars($s, 1); ?&gt;&#8221; name=&#8221;s&#8221; id=&#8221;s&#8221; /&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;cat&#8221; value=&#8221;5&#8243; /&gt;<br />
&lt;input type=&#8221;submit&#8221; id=&#8221;searchsubmit&#8221; value=&#8221;Search&#8221; /&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;</p></blockquote>
<p><strong>2. Search Subcategories Dynamically</strong></p>
<p>However, we wanted to dynamically search <strong>only the subcategories</strong> of the Recipe Category. The reason being that if you&#8217;re already in the Recipes section of the site, seeing a recipe labeled as Recipes is not helpful. However, seeing a recipe labeled as Dessert (mmm..) and Breakfast is helpful. So, each recipe that the client adds will be in a <strong>subcategory </strong>of recipes (ex. Dessert), but they won&#8217;t have to check off the checkbox next to the Recipes category itself.</p>
<p>Anyway, I&#8217;ve been looking for this solution for a long time and now, thanks to <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fbitsofink.com%2F&amp;ei=YQtjSuS9MYaEmgOgvdT4Dw&amp;usg=AFQjCNG1logmg3Pto6eFPjwQ6fHtpve3Nw">Ilan Cohen</a>, I present it to you.</p>
<p>[Replace the number 5 with the parent category.]</p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;searchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div id=&#8221;search&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221;Search&#8230; &#8221; onclick=&#8221;this.value=&#8221;;&#8221; name=&#8221;s&#8221; id=&#8221;s&#8221; /&gt;<br />
&lt;?php $categories = get_categories(&#8216;child_of=5&#8242;);<br />
$catlist = &#8221;;<br />
foreach ($categories as $cat) {<br />
$catlist.= $cat-&gt;cat_ID.&#8217;,';<br />
}<br />
$catlist.&#8217;5&#8242;;<br />
?&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;cat&#8221; value=&#8221;&lt;?php echo &#8220;$catlist&#8221;?&gt;&#8221; /&gt;<br />
&lt;input name=&#8221;" type=&#8221;image&#8221; src=&#8221;&lt;?php bloginfo(&#8216;stylesheet_directory&#8217;); ?&gt;/styles/&lt;?php echo &#8220;$style_path&#8221;; ?&gt;/search.gif&#8221; value=&#8221;Go&#8221; class=&#8221;btn&#8221; /&gt;<br />
&lt;/div&gt;&lt;!&#8211;/search &#8211;&gt;<br />
&lt;/form&gt;</p></blockquote>
<p>The code searches through all the child categories of Category 5 (Recipes). Then, you&#8217;ll see we added an additional &#8220;5&#8243; in this line: $catlist.&#8217;5&#8242;; just in case the client puts a recipe in the Recipes category, and not one of its subcategories.</p>
<p>This post was originally published at <a href="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/">How to Hack the WordPress Search Function: Search Categories and Child Categories</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

