Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
99 views
in Q2A Core by
Just wondering if I could not find it or it does not exist: A function to call to get the postid of the recent page calling.

Something like:

$postid = qa_get_active_pageid();

I have seen that pages use:

$postid = $this->content['q_view']['raw']['postid'];

for instance. But it would be handy to not always search throught $qa_content or $this->content etc. to find the postid ...

Regards
Kai
Q2A version: 1.7.4

1 Answer

0 votes
by
selected by
 
Best answer

The Q2A approach is definitely to fetch it from the content array.

Bear in mind not all pages have a postid, so qa_get_active_postid() would only make sense in the context of a question view page. It seems to be a bit overkill to do so. Furthermore, Q2A would have to preload a global variable whenever a question view page is displayed with the given post Id. Something like the qa_request() function, which is a code smell, as most (if not all) global variables.

Following the suggestion in this answer you could still add those functions to a helper. You would receive the $qa_content array (always) and you would just return the post Id applying the logic you mentioned in your question.

...