Answered: Add related tags to tag page

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

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:
Robinhood CEO downplays OpenAI concerns on tokenized stock structure
Movie: Sunshine
Movie: Sorry, Baby
Book: The Unaccountability Machine: Why Big Systems Make Terrible Decisions
Stocks making the biggest moves midday: Hershey, Chemours, Fair Isaac, Sunrun & more
Former UK Prime Minister Rishi Sunak returns to Goldman Sachs
'Revenge savings' can boost your bottom line, experts say — here's how to get started
Here's why Jim Cramer believes GE Vernova's big rally has more room to go
How to get a $250 Amazon credit just in time for Prime Day
TSA to end shoe removal policy at some airport security checkpoints, government source says