Skip to content

Instantly share code, notes, and snippets.

@iainurquhart
Created May 19, 2012 09:43
Show Gist options
  • Save iainurquhart/2730275 to your computer and use it in GitHub Desktop.
Save iainurquhart/2730275 to your computer and use it in GitHub Desktop.
pi.gwcode_catmenu.php show_empty param not honoring multiple channels using the same category group
<?php
// From line 316 pi.gwcode_catmenu.php
// subquery does not take into consideration the channel requested:
if($this->custom_fields == 'no') {
$sql = 'SELECT c.site_id, c.cat_id, c.group_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_description, c.cat_image, c.cat_order, ' .
'(' .
'SELECT COUNT(ct.entry_id) ' .
'FROM exp_channel_titles ct, exp_category_posts cp ' .
'WHERE cp.entry_id=ct.entry_id AND ct.status IN (\''.$status.'\') AND cp.cat_id=c.cat_id' .
') AS entry_count ' .
'FROM exp_categories c ' .
'WHERE c.site_id IN ('.$this->EE->db->escape_str($this->site_ids).') AND c.group_id IN ('.$this->EE->db->escape_str($this->group_ids).') ' .
'ORDER BY site_id, FIELD(c.group_id, '.$this->EE->db->escape_str($this->group_ids).'), parent_id, cat_order';
}
...
// Updated to:
if($this->custom_fields == 'no') {
// Add our channel sql if channel_id(s) are supplied
$channel_sql = ($this->channel_id != '') ? 'AND ct.channel_id IN ('.str_replace('|', ',', $this->channel_id).') ' : '';
$sql = 'SELECT c.site_id, c.cat_id, c.group_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_description, c.cat_image, c.cat_order, ' .
'(' .
'SELECT COUNT(ct.entry_id) ' .
'FROM exp_channel_titles ct, exp_category_posts cp ' .
'WHERE cp.entry_id=ct.entry_id AND ct.status IN (\''.$status.'\') AND cp.cat_id=c.cat_id ' .
$channel_sql .
') AS entry_count ' .
'FROM exp_categories c ' .
'WHERE c.site_id IN ('.$this->EE->db->escape_str($this->site_ids).') AND c.group_id IN ('.$this->EE->db->escape_str($this->group_ids).') ' .
'ORDER BY site_id, FIELD(c.group_id, '.$this->EE->db->escape_str($this->group_ids).'), parent_id, cat_order';
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment