Answered: Add related tags to tag page

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

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:
China eases IPO rules for firms developing reusable rockets
The 'Trump-class' battleship faces a large obstacle in its way: Reality
New NASA boss Isaacman says U.S. will return to the moon within Trump's term
Europe is at a 'fork in the road' between AI competition and climate, fund managers say
Over 300,000 student loan borrowers were denied a new repayment plan, court filing shows — here's why
Airlines cancel 900 more flights but disruptions from winter storm ease. Here’s what to know
Thailand and Cambodia halt fierce border conflict with second ceasefire
Coupang founder Kim Bom apologizes for data leak, pledges compensation
Putin says Russia will achieve its Ukraine aims by force if Kyiv doesn't want peace
Forget Gen Z and Millennials — the over-50s ‘Silver Spenders’ are powering investment opportunities, including these stocks