Answered: Add related tags to tag page

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

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:
Core inflation rate watched by Fed hit 2.8%, delayed September data shows, lower than expected
Trump can fire labor, employment board members without cause: Appeals court
'Trump accounts' could give your child up to $1,000 for free. Your top questions, answered
'Foolproof' nail kits and 'Holy Grail' gloves: 11 gifts for $50 or less, recommended by CNBC staff
India's largest airline melts down after new crew rest rules
At the 2026 World Cup draw, the winner is ... Donald Trump
Musk denies $800 billion SpaceX valuation reports
Trump administration waives $11 million fine for Southwest Airlines' 2022 holiday meltdown
Berkshire Hathaway is on track to lag behind the S&P 500 in Buffett's last year as CEO
The regulatory path ahead for a Netflix and Warner Bros. deal could get dicey