Answered: Add related tags to tag page

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

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:
These stocks are the most oversold in the selloff and could be due for a bounce
FAA issues order prohibiting MD-11 flights pending inspection after fiery UPS jet crash
Too early to bet against AI trade, State Street suggests 
Boeing keeps up strong delivery pace in October
Analysts call this lagging portfolio stock a buy — plus, what's behind Nvidia's decline
Experts caution against Trump’s 50-year mortgage. How to boost a traditional home loan’s affordability
29-year-old left his 6-figure tech job and opened a pizza bagel business—it brought in $20K in September
AI spending is not all equal. Wall Street rewards hyperscalers, punishes DoorDash and Duolingo
Senate passes bill to end government shutdown, sending it to House
Nasdaq falls as tech shares come under pressure again; S&P 500 is little changed: Live updates