Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
904 views
in Q2A Core by
Is there an easy way to get the postid for the current question that is being viewed? I will be using it inside qa-theme-base.php.

I'm using the following URL structure:

/123/why-do-birds-sing (requires htaccess file)

I know I could use a regular expression to get it out of the URL. But is there another way to get it with a Q2A function?

2 Answers

0 votes
by
 
Best answer

The safest way is to use: $this->content['q_view']['raw']['postid']

by
edited by
I found that 'raw' is not available when you are on the page that edits a question. It outputs the error "Notice: Undefined index: raw" because 'raw' is not in the 'q_view' array on this page.

This does not happen when you edit an answer.

Is there a way to access postid while editing a question?
by
Good point. The final release of Q2A 1.4 will include it, even if you are editing a question.
0 votes
by
This seams to work until the final release of Q2A 1.4 comes out:

 

$current_qa_request = $this->content['script_var']['qa_request'];
$current_qa_request_pieces = explode("/", $current_qa_request);
$current_postid = $current_qa_request_pieces[0];
...