Answered: Add related tags to tag page

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

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:
Trump's push for Greenland mineral rights could block China's access to rare earths
Trump withdraws 'Board of Peace' invitation to Carney in widening rift with Canada
Intel's likely to still move higher. Here's a 'no-cost' options strategy to play it
Advisors to the ultra rich say AI isn't a gamechanger for landing new clients
Shares of CSG, one of the world’s fastest-growing defense firms, jump 31% on debut
As federal ACA subsidies lapse, blue states offer their own
Social Security has 'no bankruptcy or collapse in the cards,' economist says — but benefits may change
Musk’s $1 trillion pay package renews focus on soaring CEO compensation
The U.S. states where you can retire at 65 with less than $1 million in savings
Another day another high: Gold surges past $5,000 as investors seek shelter from global risks