If you need the search module to return entries that belong to ALL of the selected categories in the advanced search form (rather than the default which selects entries in ANY of the selected categories), change this at around line 952:
/** ----------------------------------------------
/** Limit query to a specific category
/** ----------------------------------------------*/
if (isset($_POST['cat_id']) AND is_array($_POST['cat_id']))
{
$temp = '';
foreach ($_POST['cat_id'] as $val)
{
if ($val != 'all' AND $val != '')
{
$temp .= " exp_categories.cat_id = '".$DB->escape_str($val)."' OR";
}
}
if ($temp != '')
{
$temp = substr($temp, 0, -2);
$sql .= ' AND ('.$temp.') ';
}
}to:
/** ----------------------------------------------
/** Categories
/** ----------------------------------------------*/
if (isset($_POST['cat_id']) AND is_array($_POST['cat_id']))
{
if ($_POST['cat_id'][0] != 'all' && $_POST['cat_id'][0] != '')
{
// Find entries that belong to ALL selected categories
$cat_sql = "SELECT
DISTINCT(exp_weblog_titles.entry_id)
FROM exp_weblog_titles
LEFT JOIN exp_weblogs ON exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
LEFT JOIN exp_category_posts ON exp_weblog_titles.entry_id = exp_category_posts.entry_id
WHERE exp_weblogs.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
// make safe
foreach($_POST['cat_id'] as &$val)
{
$DB->escape_str($val);
}
$selected_categories = "'".implode("','", $_POST['cat_id'])."'";
$cat_sql .= "AND exp_category_posts.cat_id IN ({$selected_categories})
GROUP BY exp_category_posts.entry_id
HAVING (COUNT(exp_category_posts.entry_id) = ".count($_POST['cat_id']).") ";
$query = $DB->query($cat_sql);
if ($query->num_rows == 0)
{
return FALSE;
}
else
{
// add where condition to main query
$sql .= "AND exp_weblog_titles.entry_id IN(";
foreach ($query->result as $row)
{
$sql .= "'".$DB->escape_str($row['entry_id'])."', ";
}
$sql = substr($sql, 0, -2).")";
}
}
}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.