I am trying to override the above function to additionally filter for some information stored in postmetas.
I made a copy of the original function and added the following items to source and arguments, immediately after the initial set-up of the $selectspec array.
$selectspec['source'].=' LEFT JOIN ^postmetas ON ^postmetas.postid = ^posts.postid AND ^postmetas.title=\'custField\' AND ^postmetas.content=$';
The query now throws an error because postid is not filled in in the generated query, even though my addtion to the code has nothing to with postids and the part I added comes out correctly formed.
The generated queries contain sequences like:
...WHERE qa_posts.postid=(SELECT IF(LEFT(parent.type, 1)='A', parent.parentid, parent.postid) FROM qa_posts AS child LEFT JOIN qa_posts AS parent ON parent.postid=child.parentid WHERE child.postid=#)
...WHERE qa_posts.postid=(SELECT closedbyid FROM qa_posts WHERE postid=#)
The code works correctly when I comment out my added lines.
When listing all questions in the main view, there is no error (maybe this is handled by a different function), the problem only occurs when trying to view the details of a question.
I tried to insert my argument into the 'source' string instead of array_pushing onto 'arguments' and now the error is gone.
$selectspec['source'].=' LEFT JOIN ^postmetas ON ^postmetas.postid = ^posts.postid AND ^postmetas.title=\'custField\' AND ^postmetas.content=\''.$custValue.'\'';
So I must be doing something wrong when pushing onto the 'arguments' array ... but what?