Answered: Add related tags to tag page

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

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:
Answered: Is this software still supported or what ?
Congressional Republicans call on Tim Walz to testify on Minnesota fraud scandal
Nike shares move higher on big insider purchases by CEO Elliott Hill, director Tim Cook after down year
Khanna calls for nationwide fraud investigation after wealth tax proposal caused firestorm
Economist Mark Zandi sees the Fed surprising with three rate cuts in first half of 2026
Minimum wage just went up in 19 states—workers in one state are getting a $2 an hour raise
Student loan forgiveness is taxable again: Start planning for the 'tax bomb,' CFP says
Novo Nordisk enters 2026 on the defense as it faces a ‘must-win’ battle in the U.S. market
New Year's resolutions rarely work, neuroscientist says: Here's a smarter way to build new habits
2026 will bring more GLP-1 weight loss pills — and new habits. These stocks are poised to benefit