Answered: Add related tags to tag page

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

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:
The SALT deduction limit is $40,400 for 2026. Here's how to maximize it
Anthropic will be 'most ridiculous IPO' of year, analyst says
Cramer says higher rates are splitting the market in two — and AI stocks have a big advantage
Levi Strauss hikes profit guidance after tariff refunds, but its sales outlook is less optimistic
SpaceX’s plans to buy more Nvidia GPUs is keeping Jim Cramer bullish on the chip stock
Barclays sees big haircare gains for this consumer stock as shoppers prioritize self-care
Trump trade chief Greer reports higher cash holdings as law firm pay topped $650K
Movie: The Monster Club
Movie: Resident Evil: Afterlife
Movie: Verity