Answered: Add related tags to tag page

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

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:
Fanatics to launch sports media and entertainment studio
Does it really matter who ends up owning Warner Bros.? Media exec Tom Rogers breaks it down
BNY raises profit target as CEO Robin Vince says 'turnaround' is taking hold
More drivers have $1,000-plus car loan payments. Here's what buyers can expect in 2026
New York offshore wind project to resume construction after judge lifts Trump suspension
Why Jim Cramer is bullish on Goldman Sachs and Morgan Stanley
South Korea's ex-president Yoon given 5-year jail term in first ruling over martial law
AI startup Replit launches feature to vibe code mobile apps
OpenAI tells investors to brace for 'deliberately outlandish' claims from Musk ahead of trial
Russia says it's monitoring Trump's 'extraordinary' push to take over Greenland