Answered: Add related tags to tag page

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

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:
Costco adds Biden Commerce Sec. Gina Raimondo to board on heels of Trump tariff lawsuit
$208 million wiped out: Yieldstreet investors rack up more losses as firm rebrands to Willow Wealth
S&P 500 tries to hang onto gains ahead of big events next week that could move 3 stocks
Apple announces departure of general counsel and policy chief
India's largest airline melts down after new crew rest rules
4 'good enough' financial moves to reach your goals with 'less time and hassle,' from a money expert
S&P 500 quietly rebounds to near a new record. Where to next after a quick round trip?
At the 2026 World Cup draw, the winner is ... Donald Trump
Judge finalizes remedies in Google antitrust case
Trump administration waives $11 million fine for Southwest Airlines' 2022 holiday meltdown