Answered: Add related tags to tag page

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

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:
Why institutional investors are returning to retail 'in a very big way'
Bitcoin's high-conviction holders are turning into sellers as the crypto's price hits new lows
Trump's 'big beautiful bill' has a 'double taxation' trap for top earners, tax lawyers say
CrowdStrike narrowly beats estimates on AI tailwinds, but stock falls 10%
Interesting Quiet/Lesser Known Places To Go In Europe
Tell Me Your Favorite ***** of the Day Websites
As the largest World Cup ever kicks off, health officials are focused on more than Ebola
Blackstone restricts flagship fund withdrawals as private asset fears reemerge
Inside Wealth: Soaring stocks created 2 million new millionaires around the world last year
Eli Manning weighs in on Giants QB Jaxson Dart's Trump rally fallout