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

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Apr 29: Q2A 1.5.2

How do I get the userid of the author of a post?

+2 votes
Basically I am adding Gravatar support to my the question and answer view and I need to be able to extract the userid of the author of the post (be it a question, answer or comment) so I can call the following function to get their email address:

qa_db_single_select($qa_db, qa_db_user_account_selectspec($userid, true));

Does anyone know a simple way of doing this?
asked Jul 21, 2010 in Q2A Core by anonymous

1 Answer

0 votes
 
Best answer
Currently the raw userid of the author of the post is not passed through to the theme layer. But it is available in qa_post_html_fields(...) in qa-app-format.php, as $post['userid'], so you could do something with it there.

But a better way would be to modify qa_db_posts_basic_selectspec(...) in qa-db-selects.php to extract the author's email address as part of the main query. That will save you having to run lots of individual queries to get the email address of the author for each post. Try adding this:

$selectspec['columns']['email']='BINARY ^users.email';

... after ...

$selectspec['columns']['handle']='BINARY ^users.handle';

Having done that you should be able to access $post['email'] directly from qa_post_html_fields(...) and can use that to add the gravatar HTML as a prefix or suffix to $fields['who']['data'] after it is assigned by the call to qa_who_to_html(...)
answered Jul 21, 2010 by gidgreen
Yes indeed, avatars (via Gravatar or otherwise) are certainly on the roadmap.
Sounds good. You could have radio buttons in the users profile to upload an Avatar or use Gravatar instead. I am very impressed with this project, I look forward to contributing to it in the future.