@@ -148,11 +148,19 @@ public function get_ideas($number = 10, $sort = 'date', $sort_direction = 'DESC'
148148 $ where .= ' AND i.idea_votes_up > i.idea_votes_down ' ;
149149 }
150150
151+ // Only get approved topics
152+ $ where .= ' AND t.topic_visibility = ' . ITEM_APPROVED ;
153+
154+ // Only get ideas that are actually in the ideas forum (not ones that have been moved)
155+ $ where .= ' AND t.forum_id = ' . (int ) $ this ->config ['ideas_forum_id ' ];
156+
151157 // Count the total number of ideas for pagination
152158 if ($ number >= $ this ->config ['posts_per_page ' ])
153159 {
154160 $ sql = 'SELECT COUNT(i.idea_id) as num_ideas
155- FROM ' . $ this ->table_ideas . " i
161+ FROM ' . $ this ->table_ideas . ' i
162+ INNER JOIN ' . $ this ->table_topics . " t
163+ ON i.topic_id = t.topic_id
156164 WHERE $ where " ;
157165 $ result = $ this ->db ->sql_query ($ sql );
158166 $ num_ideas = (int ) $ this ->db ->sql_fetchfield ('num_ideas ' );
@@ -162,9 +170,6 @@ public function get_ideas($number = 10, $sort = 'date', $sort_direction = 'DESC'
162170 $ this ->idea_count = $ num_ideas ;
163171 }
164172
165- // Only get approved topics
166- $ where .= ' AND t.topic_visibility = ' . ITEM_APPROVED ;
167-
168173 if ($ sortby !== 'TOP ' && $ sortby !== 'ALL ' )
169174 {
170175 $ sql = 'SELECT t.topic_last_post_time, t.topic_status, i.*
@@ -710,7 +715,8 @@ public function delete_orphans()
710715 // Find any orphans
711716 $ sql = 'SELECT idea_id FROM ' . $ this ->table_ideas . '
712717 WHERE topic_id NOT IN (SELECT t.topic_id
713- FROM ' . $ this ->table_topics . ' t) ' ;
718+ FROM ' . $ this ->table_topics . ' t
719+ WHERE t.forum_id = ' . (int ) $ this ->config ['ideas_forum_id ' ] . ') ' ;
714720 $ result = $ this ->db ->sql_query ($ sql );
715721 $ rows = $ this ->db ->sql_fetchrowset ($ result );
716722 $ this ->db ->sql_freeresult ($ result );
0 commit comments