Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

how to make a category not to list under list questions?

+2 votes
asked Nov 23, 2016 in Q2A Core by teju2friends
Q2A version: 1.8

1 Answer

+2 votes
answered Nov 23, 2016 by pupi1985
edited Nov 28, 2016 by pupi1985

You'll have to hack the core.

1. Edit file db/selects.php

2. Change this part of the code in function qa_db_qs_selectspec:

$selectspec=qa_db_posts_basic_selectspec($voteuserid, $full);

$selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE ".

into this

$selectspec = qa_db_posts_basic_selectspec($voteuserid, $full);

$hiddenCategoryIds = array(1, 2);
$hideInPages = array('', 'activity', 'questions');
if (in_array(qa_request(), $hideInPages) && !empty($hiddenCategoryIds)) {
    $sql = '(^posts.categoryid NOT IN (' . implode(',', $hiddenCategoryIds) . ') OR ^posts.categoryid IS NULL) AND ';
} else {
    $sql = '';
// echo qa_request();

$selectspec['source'] .= " JOIN (SELECT postid FROM ^posts WHERE " .

You can get the category IDs from the admin panel in the categories section. Navigate to the category you want to hide and then check the URL. It should look like this:


So 7 is the category ID. Make sure you replace the content of the array with that ID:

$hiddenCategoryIds = array(7);

The $hideInPages array controls in which pages you want to hide them. If you don't want t see them in any additional page, then uncomment (remove the // from the echo qa_request();) and navigate to that page. You will most likely text in the top left corner of the page. Just add that text to the $hideInPages array. Then comment the uncommented line again.

Note about the /activity page: 

You will see the core has also these functions:


You'll have to perform similar edits to those functions in order to filter out all the questions (asked, answered, commented and edited). This answer just tackles the "asked" ones but fixing the rest should be trivial based on how the "asked" ones are fixed.

This is very very dirty and I wouldn't advise to hack the core that much... but it should get the work done.

commented Nov 28, 2016 by pupi1985
It is extremely unlikely that filtering out some results in that query would result in broken HTML, which I happen not be able to reproduce locally. Not much I can do. However, you can install Q2A from scratch on a test server, apply the changes and you will most likely see it doesn't generate that error. If it does, then you will have the step by step instructions to reproduce this which is what I need :)
commented Nov 28, 2016 by teju2friends
@pupi1985, OOps, I didn't meant broken html!
After applying fix, the categories were showing different questions(In the ways, question list in categories was broken).  I should have been more explicit.
commented Nov 28, 2016 by pupi1985
I see now. The issue was I told to delete up to (including) the line with the: qa_db_categoryslugs_sql_args. That was a copy/paste issue and should have not been included to be replaced. So the addition should work, just don't remove that last line (I've updated the answer anyway).

Also see the note about the /activity page.

Finally, remember to add each of the pages you want these "exceptions" to be run (e.g.: if you want to hide questions under a given category then you have to add the output of the qa_request() in the $hideInPages array).