Answered: Add related tags to tag page

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

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:
Target to remove synthetic color from cereals by May end
Netflix ditches deal for Warner Bros. Discovery after Paramount’s offer is deemed superior
Core wholesale prices rose 0.8% in January, much more than expected
Jim Cramer's top 10 things to watch in the stock market Friday
Gen Z is embracing the prenup, says family law attorney: ‘The taboo of divorces is long gone’
Answered: Can I upload video in q2a by a plugin?
The digital front: Iran’s internet down for over 60 hours amid reports of cyberattacks
Amazon says drone strikes damaged 3 facilities in UAE and Bahrain
The Strait of Hormuz crisis explained: What it means for global shipping
Movie: A Useful Ghost