How to limit the search to certain categories

Frequently Asked Questions (read only)

How to limit the search to certain categories

Postby FI-DD » Wed Jul 19, 2006 6:41 pm

With this little hack you can define which categories you want to search in.



It seems this hack only works using MySQL.



Open search.php and find this:

Code: Select all
$where[] = 'and';




add below:

Code: Select all
   $allowed_categories = array("1", "2", "3"); //Enter the categories you want to search in



   foreach($allowed_categories as $single){

      $where[] = 'category =~ %'.$single.'%';

      $where[] = 'or';

   }

   

   $count = count($where)-1;

   unset ($where[$count]);

      

   foreach ($allowed_categories as $k => $v){

         for ($i = 0; $i < 10; $i++){

            if (!in_array($v.$i, $allowed_categories)){

               $where[] = 'and';

               $where[] = 'category !~ %'.$v.$i.'%';

            }



            if (!in_array($i.$v, $allowed_categories)){

               $where[] = 'and';

               $where[] = 'category !~ %'.$i.$v.'%';

            }

         }

      }

   $where[] = 'and';




Change the first line of this code by adding the IDs of your categories.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Return to FAQ



Who is online

Users browsing this forum: No registered users and 0 guests