In looking at your link line, it doesn't look like your $query is being built correctly. You don't seem to have the initial query. For example, in an OOB 9.30 environment, the Expression in the category link line is as follows:
$query="active=true and name~=\"tbd\" and name~=\"example\" and (name isin $G.auth.categories or name=\"change\")"
if (not (null(category in $File))) then $query+=(" and name#\""+category in $File+"\"")
It seems that you should start with something like that and perhaps add a line:
if (not (null(project.id in $File))) then $query+=" and project.id=project.id in $File"