Answered: Add related tags to tag page

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

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:
Bank of America is betting on these stocks, including one Big Tech laggard, in the first quarter of 2026
Buffett backs new CEO Greg Abel with 'huge endorsement' in CNBC interview
Behind the mesh curtain: Why airline class wars will intensify in 2026
Buffett says Berkshire has the best odds of any company for lasting 100 more years as he hands over reins
Watch Trump's full comments following the U.S. strike against Venezuela
Estate planning helps 'forestall bad outcomes,' author says — you need some key documents even at age 18
Crude prices rise more than 1% as Maduro overthrow casts uncertainty over oil-rich Venezuela
Who controls Venezuela's oil now? What Maduro's arrest means for energy markets
Ousted Venezuelan leader Maduro gets Julian Assange's lawyer to represent him in drug case
Amazon lets some users chat with Alexa+ on the web in bid to take on ChatGPT