Answered: Add related tags to tag page

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

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:
Iran war threatens $11.7 trillion global travel industry as passengers get caught in crossfire
How China is challenging the U.S. to become the next great space power
Here are 3 themes that drove another challenging week on Wall Street
Guided tours of museums and sights in Paris?
The Slinky to Poofy Continuum
The Pitt: 3:00 P.M.
Star Trek: Starfleet Academy: 300th Night
LUMIÈRE!
Trump urges Latin American leaders to use military to help the U.S. fight cartels
This homebuilding play is one of the most oversold stocks amid this week’s market turmoil