Exclude Certain WordPress Categories from Being Searched

March 18, 2009

You may not want all of your categories to appear in your search results. For example, if you’ve set up a sidebar asides category, you may not want those short snippets tangling up with your results. To remove a category, first open up your theme’s functions.php file (Or create a blank file with that name if your theme doesn’t have one); Then paste the following code at the end: <?php function SearchFilter($query) { if ($query->is_search) { $query->set('cat','8,16'); } return $query; } add_filter('pre_get_posts','SearchFilter'); ?> Simply... [Read the full story]

Highlight the Search Terms in WordPress Search Results

March 18, 2009

When you search on Google or any other major search engine, the words you searched for are highlighted in the results to make it easier for you to scan. We can do the same with your wordpress search results page. In your search.php, search for the following: <?php the_title ();?> This is the code for showing the title of each of the results. In the default theme, it will be wrapped up in a line like this: <h3 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink()... [Read the full story]

Show the Number of Results in WordPress search

March 18, 2009

The typical WordPress search results page has the title “Search Results.” It’s not very helpful, but we can make it much more dynamic, very easily. Let’s change our title to something like “Search Result for search terms – 8 Articles” Open your search template file, search.php. In it, search for the following: <h2 class="pagetitle">Search Results</h2> Now replace this with: <h2 class="pagetitle"> Search Results for <?php /* Search Count */ $allsearch = &new... [Read the full story]

Disable search engine indexing on a particular category

January 25, 2009

How to disable search engine indexing on a particular category? First get the ID of the category you’d like to be not indexed by search engines. In this exemple, I assume your category id is 18. Open your header.php file and paste the following code between the <head> and </head> tags: <?php if ( is_category('18') || in_category('18') ) { echo '<meta name="robots" content="noindex">'; } That’s all. With the above code, we made sure that no post from category with the ID 18 as well as category... [Read the full story]

Limit search to specific categories of wordpress

January 23, 2009

If for some reason, you’d like to exclude some categories from searches, you have to tweak WordPress a bit because there’s no built-in solution to this problem. Happilly, here’s a code to do that job. Replace the categories IDs on line 3 and paste the following code on your search.php template: <?php if( is_search() ) : $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("s=$s&paged=$paged&cat=1,2,3"); endif; ?>  Read More →