Answered: Add related tags to tag page

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

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:
S&P 500 rises to start a holiday-shortened week, led by tech: Live updates
Mercedes-Benz agrees to $149.6 million settlement with U.S. states over excess diesel emissions
Alphabet to acquire data center and energy infrastructure company Intersect
Instacart ends AI-driven pricing tests that pushed up costs for some shoppers
Motive, an Alphabet-backed fleet management software company, files for IPO
Crypto exchange Kraken plans to offer prediction markets in 2026: CNBC Crypto World
This convenience store chain is in a long-term upward trend with no signs of slowing, charts show
Monetizers vs manufactures: How the AI market could splinter in 2026
Exclusive: Nvidia buying AI chip startup Groq's assets for about $20 billion in largest deal on record
Flash flooding in northern California leads to soaked roads, water rescues and one death