Answered: Add related tags to tag page

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

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:
Inflation dominates Powell's remarks, pressures stocks. Plus, big earnings tonight
Thursday's big stock stories: What’s likely to move the market in the next trading session
As Americans struggle with rising costs, many states’ unemployment benefits fall short, analysis finds
Disney embarks on new chapter as Josh D'Amaro takes over as CEO
Social Media Poster - Auto-share your Q2A content everywhere
Scarpetta: Full first Season
Paradise: Jane
Trump warns to 'blow up' South Pars gas field in Iran if strikes against Qatar energy continue
Fed holds interest rates steady — here’s what that means for consumers
Vice President Vance to meet with oil industry as White House plans more actions to address fuel prices