Answered: Add related tags to tag page

Post date: 2025-05-09 04:21:33
Views: 18

I changed the query to a more simple one and do the rest in php.

function get_tag_related_tags($tag) {
    $query = "
        SELECT tags
        FROM ^posts
        WHERE type='Q' AND tags LIKE CONCAT('%', # , '%')
    ";
    $results = qa_db_read_all_assoc(qa_db_query_sub($query, $tag));
    
    $tag_counts = ];
    foreach ($results as $row) {
        $tags = explode(',', $row'tags']);
        foreach ($tags as $t) {
            $t = trim($t);
            if ($t !== $tag && $t !== '') {
                if (!isset($tag_counts$t])) {
                    $tag_counts$t] = 0;
                }
                $tag_counts$t]++;
            }
        }
    }

    arsort($tag_counts);

    $related_tags = ];
    $i = 0;
    foreach ($tag_counts as $t => $count) {
        $related_tags] = 'tag' => $t, 'count' => $count];
        $i++;
        //if ($i >= 10) break;
    }

    return $related_tags;
}

Now it works.

Please click Here to read the full story.
 
Other Top and Latest Questions:
[New Premium Theme] Qlassy Theme with complete features - Beta Version
RCI Hospitality strip club execs bribed tax auditor with comped dances: NY AG
Charlie Kirk shooting suspect Tyler Robinson charged with murder, faces possible death penalty
If you bought your house before 2005, you could be sitting on a goldmine
Microsoft, Nvidia, other tech giants plan over $40 billion of new AI investments in UK
Amazon CEO Jassy says company is reducing bureaucracy, which is ‘anathema’ to innovation
China keeps tight grip on rare earths, costing at least one company 'millions of euros'
StubHub to price IPO at $23.50, valuing company at $8.6 billion
The UK's top fintech companies: 2025
Stock futures are little changed as traders await key Fed rate outlook: Live updates