Answered: Add related tags to tag page

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

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:
Russia and Ukraine agree local truce to allow repairs at Europe’s largest nuclear power plant
UK PM Keir Starmer suffers major blow after his party comes third in key vote
Trump Media in talks to spin off Truth Social from DJT into independent stock
Gen Z is embracing the prenup, says family law attorney: ‘The taboo of divorces is long gone’
Pakistan bombs targets in Afghan cities, minister calls it 'open war'
The Strait of Hormuz is facing a blockade. These countries will be most impacted
Answered: Can I upload video in q2a by a plugin?
South Korea defense stocks soar with heavyweight Hanwha Aerospace surging 25% as traders react to Iran war
The Pitt: 2:00 P.M.
Book: finnegans wake