Answered: Add related tags to tag page

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

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:
Illegal NBA gambling busts put sportsbooks on the defense
Taco Bell tries to woo younger customers with Live Más Café's flashy beverages
Sell into the Beyond Meat frenzy, says one of the few analysts still covering the stock
What a cut in Reliance's Russian crude purchases would mean for India
New York Attorney General Letitia James set to plead not guilty in mortgage fraud case
Family offices fear dollar depreciation, lower investment returns in wake of tariffs
Traders get their wish as inflation numbers give Fed greenlight to cut twice more this year
How to tackle private credit’s ‘cockroaches’ as contagion fears build
AI spending is boosting the economy, but many businesses are in survival mode
Chinese rivals to Meta's AI glasses are piling up. How Goldman is playing the trend