Posted in Featured, jQuery, php

Like this post? Share It :
  • Print
  • email
  • PDF
  • Google Bookmarks
  • Facebook
  • Twitter
  • MySpace
  • Yahoo! Buzz
  • del.icio.us
  • Digg
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Reddit
  • Technorati
  • Design Float
  • RSS

How To Display Only Specific Category In Search Results

 

There are times when you make some specific category for just review or promotional stuff and would not want to get that included in your search results. This simple tutorial will help you to include only specified categories in your search results, so your users will have more accurate search results.

style=”text-align: center;”>

Procedure:

style=”color: rgb(255, 0, 0);”>Note: Do take backup of the files before you try this.

01. Login to wordpress administration panel and go to Posts => Categories

02. Once there find the category you want to know the ID for and hover over it, you should see edit link. Right click on it and select Copy Link Location (in firefox) and then open a new tab and paste it there. You should see your category ID as tag_ID=xx. That xx is your category id.

03. Place this code in your functions.php file:

class=”code”>function searchcategory($ query) {
/> if ($ query->is_search) {
/> $ query->set('cat','3,7');
/> }

return $ query;
/> }

add_filter(‘pre_get_posts’,'searchcategory’);

 

03. Simply change 3 and 7 to the categories you want to use for your search results, you can add as many as you want by separating them with commas (,).

This concludes this simple and useful tutorial. Hope you like it.


TutZone

Like this post? Share It :
  • Print
  • email
  • PDF
  • Google Bookmarks
  • Facebook
  • Twitter
  • MySpace
  • Yahoo! Buzz
  • del.icio.us
  • Digg
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Reddit
  • Technorati
  • Design Float
  • RSS

Related posts:

  1. Five Unique Search Engines That Can Help You More Effectively
  2. A simple CSS based usability tip for search buttons
  3. How To Display Adsense Ads On Posts Older Than 4 Days
  4. Seven Premium Style jQuery Plugins And Tutorials To Display Images On Websites

Comments are closed.