Answered: Add related tags to tag page

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

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:
Opinion: Block's layoffs might just be the biggest story of a tumultuous week. Here's why
Smartphone market poised for 'sharpest decline on record' in 2026
UK PM Keir Starmer suffers major blow after his party comes third in key vote
Robust Search within recovered data
Movie: The Last Sacrifice
A Knight of the Seven Kingdoms: The Hedge Knight: The Morrow Books Included
OpenAI announces $110 billion funding round with backing from Amazon, Nvidia, SoftBank
Apple appears to be sitting out the AI arms race. Will the strategy work?
Trump angering MAHA with glyphosate order gives Democrats an opening
Private equity enters its 'Darwinian' era as experts warn some funds face extinction