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

Get the count of questions related to a tag

+1 vote
What query do I need to use to get the count of questions related to a tag?

I added some tags to the sidebar, but I'd like to add just to the right the amount of questions that use that tag as well.
asked Oct 7, 2011 in Q2A Core by Aslan

1 Answer

+1 vote
Something like this:

$count = qa_db_read_one_value(
    qa_db_query_sub(
        'SELECT COUNT(postid) FROM ^posttags WHERE wordid=#',
        $tagid
    ),true
);
answered Oct 7, 2011 by NoahY
Noah, I guess this is within a post, isn't it? I actually need to get the values globally since they'll be placed in the sidebar, just aside thir corresponding tags. Any guess?
No, that's anywhere... all you need is a word id for each tag; if your widget is showing tags, you must have the word id for each tag, no?  Just pass it in as $tagid, then echo the output, $count.