Answered: Add related tags to tag page

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

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:
These names on Josh Brown's best stocks list showed strength during last week's volatility. One is forming a 'golden cross'
Friday's jobs report will be delayed because of the partial government shutdown
Answered: I have a project for you... (Developer)
Housing affordability isn't just hurting buyers: More homeowners are falling behind on their mortgages
Barclays AAdvantage cards are moving to Citi: What cardholders should know
Erratic behavior in bitcoin, silver and memory stocks threatens to unnerve bull market
Why the catastrophe bond market is so hot right now
Uber reports 20% revenue growth in fourth-quarter, fueled by food delivery
Software stock rout shocks Street: 'Nowhere to hide'... 'Morass of gloom'
Fed pick: Tillis doubles down on Warsh blockade over concerns about central bank independence