Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
in Q2A Core by


each time user create a new post, our support team receive an email notification. I was asked to adjust an email with a category name to which question is linked.

I have found a variables where the email is constructed, however I do not know what is the name of category field

        'q_posted_body' => "A new question has been asked by ^q_handle:\n\n^open^q_title\n\n^q_content^close\n\nClick below to see the question:\n\n^url\n\nThank you,\n\n^site_title",
        'q_posted_subject' => '^site_title has a new question',

The category I talk about you can see below

How can I figure out the name of a category field?

Q2A version: 1.7.1

1 Answer

+4 votes
Best answer

I have managed to do that.

1. I have updated Subject line to:

        'q_posted_subject' => '^site_title har fået et nyt indlæg i ^q_categoryname'

2. I have made a lookup in database to get a category name. I have made little update to qa-include/plugins/qa-event-notify.php:

                if (qa_opt('notify_admin_q_post')) {
                    $q = "SELECT pcat.title from qa_categories as cat join qa_categories as pcat ON pcat.categoryid = cat.parentid where cat.categoryid = " . $params['categoryid'];
                    $res = qa_db_read_one_assoc(qa_db_query_sub($q));
                    $catname = isset($res['title']) ? $res['title'] : '';

                    qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array(
                        '^q_categoryname' => $catname,
                        '^q_handle' => $sendhandle,
                        '^q_title' => $params['title'], // don't censor title or content here since we want the admin to see bad words
                        '^q_content' => $params['text'],
                        '^url' => qa_q_path($params['postid'], $params['title'], true),

Good solution.
However, event-notify.php may be changed in the future.
It would be safer to override qa_send_notification() function with your new plugin.

For example:
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false) {
  if($subject == qa_lang('emails/q_posted_subject')) {
    $subject = '^site_title har fået et nyt indlæg i ^q_categoryname';
    $subs['^q_categoryname'] = $catname;
  return qa_send_notification_base($userid, $email, $handle, $subject, $body, $subs, $html);
thanks, I will definitely need to make a patch!