Answered: Add related tags to tag page

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

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:
Dutch halt state intervention at Chinese-owned chipmaker Nexperia, paving way for exports to resume
Trump administration takes further steps to dismantle Department of Education
Why superior speed isn't selling EVs
Blip, dip, pullback or the beginning of the end? Global investors weigh in on stock sell-off
Tesla obtains permit to operate ride-hail service in Arizona
From $1 trillion spending to F-35s, U.S.-Saudi pledges aren't done deals yet
TJ Maxx and Marshalls owner hikes outlook as CEO says holiday season is off to a 'strong start'
The stock market is counting on Nvidia. Here are the 'whisper numbers' the chip giant must deliver
Porsche reveals all-electric Cayenne SUV, 'most powerful' production vehicle ever made by sports car company
Stocks rally, led by Alphabet jump; Wall Street awaits Nvidia earnings: Live updates