Answered: Add related tags to tag page

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

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:
Melius upgrades Chevron, sees upside from Venezuela and exploration push
S&P 500 finds itself once again unable to surmount the 7,000 threshold
Alibaba unveils Qwen3.5 as China’s chatbot race shifts to AI agents
Curling scoreboard question
Abbott Elementary: Candygrams
Abbott Elementary: Mall Part 3: Heroes
Abbott Elementary: Birthday
Book: Purgatorio: Canto 05
The Pitt: 12:00 P.M.
Netflix grants Warner Bros. Discovery 7-day waiver to reopen deal talks with Paramount Skydance